fix sanitize_query
Do not change what the length of string is. It is a receipe for bugs.
@@ -56,15 +56,15 @@ int query_sanitize( char buf[], size_t buflen, const char query[] ) {
size_t len;
size_t i;
- len = strlen( query ) + 1;
+ len = strlen( query );
- if( len >= buflen ) {
+ if( (len + 1) > buflen ) {
// Output buffer too small
return 1;
}
// Convert to lower case
- for( i = 0; i < len; ++i ) {
+ for( i = 0; i <= len; ++i ) {
buf[i] = tolower( query[i] );
}
