library/src/utility/BP-StringUtilities.cc
// This attempts to determine if a string is reasonable with regard to JSON string output.
This attempts to determine if a string is reasonable with regard to JSON string output.
This attempts to determine if a string is reasonable with regard to JSON string output .
BP_BOOL BP_StringIsReasonableForJSONOutputString
(
	char * json_output_string_to_analyze,
	size_t json_output_string_len
)
{
	if(!BP_StringIsReasonablePrintableString(json_output_string_to_analyze, json_output_string_len, BP_FALSE, BP_FALSE))
		return BP_FALSE;
	BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config;
	BP_ZERO_STACK(ascii_config);
	ascii_config.count_ascii                      = BP_TRUE;
	P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis
	(
			(unsigned char *) json_output_string_to_analyze,
			(size_t)          json_output_string_len,
			&ascii_config
	);
	if(!buff_analysis)
		return BP_FALSE;
	if
	(
			buff_analysis->ascii->char_counts['\\'] ||
			buff_analysis->ascii->char_counts['`' ] ||
			buff_analysis->ascii->char_counts['"' ] ||
			buff_analysis->ascii->char_counts['\'']
	)
	{
		BP_DestroyBufferAnalysis(buff_analysis);
		return BP_FALSE;
	}
	BP_DestroyBufferAnalysis(buff_analysis);
	return BP_TRUE;
}
BP_BOOL BP_StringIsReasonableForJSONOutputString ( char * json_output_string_to_analyze , size_t json_output_string_len ) { if ( ! BP_StringIsReasonablePrintableString ( json_output_string_to_analyze , json_output_string_len , BP_FALSE , BP_FALSE ) ) return BP_FALSE ; BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config ; BP_ZERO_STACK ( ascii_config ) ; ascii_config . count_ascii = BP_TRUE ; P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis ( ( unsigned char * ) json_output_string_to_analyze , ( size_t ) json_output_string_len , & ascii_config ) ; if ( ! buff_analysis ) return BP_FALSE ; if ( buff_analysis -> ascii -> char_counts [ ' \\ ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' ' ] || buff_analysis -> ascii -> char_counts [ ' \' ' ] ) { BP_DestroyBufferAnalysis ( buff_analysis ) ; return BP_FALSE ; } BP_DestroyBufferAnalysis ( buff_analysis ) ; return BP_TRUE ; }
This attempts to determine if a string is reasonable with regard to JSON string output.
This attempts to determine if a string is reasonable with regard to JSON string output .
// attempt to verify that the string is reasonable first // create ascii configuration // set some flags in the structure to count ascii (we already counted invalid with our initial check) // attempt to generate analysis // ensure we h ave a buffer analysis // ensure buffer doesn't have any special chars which could // play havoc with later parsing. // destroy the buffer analysis // return indicating the path is bad // destroy the buffer analysis // return indicating success