library/src/databases/bpdb/BP-DBStringFilters.cc
// checks to see if a string is reasonable for a mariadb comparison operator
checks to see if a string is reasonable for a mariadb comparison operator
checks to see if a string is reasonable for a mariadb comparison operator
BP_BOOL BP_StringIsReasonableForMariadbComparisonOperatorDB(char *buffer, size_t len)
{
	if(!buffer || !len)
		return BP_FALSE;
	if(!BP_StringIsReasonablePrintableString(buffer, len, BP_FALSE, BP_FALSE))
		return BP_FALSE;
	char * internal_bpdb_comparison_operator_string_array[]
	{
			"!=",
			"<",
			"<=",
			"<=>",
			"=",
			">",
			">=",
			"!",
			"&&",
			"XOR",
			"||",
			NULL
	};
	P_BP_LINKL valid_comparison_operators = BP_CreateLinkL(".", BP_TRUE);
	size_t str_iter = 0;
	for(; internal_bpdb_comparison_operator_string_array[str_iter]; str_iter++)
	{
		tq_strdup(valid_comparison_operators, internal_bpdb_comparison_operator_string_array[str_iter], BPLN);
	}
	char *tmp_buff = bpstrndup(buffer, len);
	if(!BP_LinkLSearchForString(valid_comparison_operators, tmp_buff, len))
	{
		bpfree(tmp_buff);
		BP_DestroyLinkL(valid_comparison_operators, BP_TRUE);
		return BP_FALSE;
	}
	bpfree(tmp_buff);
	BP_DestroyLinkL(valid_comparison_operators, BP_TRUE);
	return BP_TRUE;
}
BP_BOOL BP_StringIsReasonableForMariadbComparisonOperatorDB ( char * buffer , size_t len ) { if ( ! buffer || ! len ) return BP_FALSE ; if ( ! BP_StringIsReasonablePrintableString ( buffer , len , BP_FALSE , BP_FALSE ) ) return BP_FALSE ; char * internal_bpdb_comparison_operator_string_array [ ] { " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , " " , NULL } ; P_BP_LINKL valid_comparison_operators = BP_CreateLinkL ( " " , BP_TRUE ) ; size_t str_iter = 0 ; for ( ; internal_bpdb_comparison_operator_string_array [ str_iter ] ; str_iter ++ ) { tq_strdup ( valid_comparison_operators , internal_bpdb_comparison_operator_string_array [ str_iter ] , BPLN ) ; } char * tmp_buff = bpstrndup ( buffer , len ) ; if ( ! BP_LinkLSearchForString ( valid_comparison_operators , tmp_buff , len ) ) { bpfree ( tmp_buff ) ; BP_DestroyLinkL ( valid_comparison_operators , BP_TRUE ) ; return BP_FALSE ; } bpfree ( tmp_buff ) ; BP_DestroyLinkL ( valid_comparison_operators , BP_TRUE ) ; return BP_TRUE ; }
checks to see if a string is reasonable for a mariadb comparison operator
checks to see if a string is reasonable for a mariadb comparison operator
// ensure we have a directory and a length // attempt to verify that the string is reasonable first // statically defined set of strings // create list of valid comparison operators // declare string iterator // walk str iter and create linkl // add operator // duplicate tmp_buff before compare // if we can't find the buffer, destroy linkl and exit // destroy the linkl before exiting success // return indicating that the operator has been found