Limit the length of the patterns on LIKE and GLOB to avoid problems with

deep recursion and N^2 behavior. (CVS 3950)

FossilOrigin-Name: 42e6c826998e69462462b0787d3650246d36f3b5
This commit is contained in:
drh
2007-05-08 15:34:47 +00:00
parent a0206bc81c
commit beb818d1fd
4 changed files with 32 additions and 12 deletions
+15 -3
View File
@@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.149 2007/05/08 15:15:02 drh Exp $
** $Id: func.c,v 1.150 2007/05/08 15:34:48 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -535,8 +535,19 @@ static void likeFunc(
int argc,
sqlite3_value **argv
){
const unsigned char *zA = sqlite3_value_text(argv[0]);
const unsigned char *zB = sqlite3_value_text(argv[1]);
const unsigned char *zA, *zB;
/* Limit the length of the LIKE or GLOB pattern to avoid problems
** of deep recursion and N*N behavior in patternCompare().
*/
if( sqlite3_value_bytes(argv[1])>SQLITE_MAX_LIKE_PATTERN_LENGTH ){
sqlite3_result_error(context, "LIKE or GLOB pattern too complex", -1);
return;
}
zA = sqlite3_value_text(argv[0]);
zB = sqlite3_value_text(argv[1]);
int escape = 0;
if( argc==3 ){
/* The escape character string must consist of a single UTF-8 character.
@@ -556,6 +567,7 @@ static void likeFunc(
#ifdef SQLITE_TEST
sqlite3_like_count++;
#endif
sqlite3_result_int(context, patternCompare(zA, zB, pInfo, escape));
}
}