1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-15 11:41:13 +03:00

Strengthen the defense against OOM in the instr() SQL function.

FossilOrigin-Name: a0971e713682a73d8c7c20511db256c20d2f6388
This commit is contained in:
drh
2016-12-30 15:16:20 +00:00
parent 5f4ade0473
commit 1d081ab39e
3 changed files with 10 additions and 9 deletions

View File

@@ -204,13 +204,14 @@ static void instrFunc(
if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){
zHaystack = sqlite3_value_blob(argv[0]);
zNeedle = sqlite3_value_blob(argv[1]);
assert( zNeedle!=0 );
assert( zHaystack!=0 || nHaystack==0 );
isText = 0;
}else{
zHaystack = sqlite3_value_text(argv[0]);
zNeedle = sqlite3_value_text(argv[1]);
isText = 1;
if( zNeedle==0 ) return;
assert( zHaystack );
if( zHaystack==0 || zNeedle==0 ) return;
}
while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){
N++;