/ Check-in [a0971e71]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Strengthen the defense against OOM in the instr() SQL function.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:a0971e713682a73d8c7c20511db256c20d2f6388
User & Date: drh 2016-12-30 15:16:20
Context
2016-12-30
17:40
Fix a crash that could occur following an OOM in the group_concat() function if the second argument is an SQLITE_BLOB value. check-in: 14d855d2 user: dan tags: trunk
15:16
Strengthen the defense against OOM in the instr() SQL function. check-in: a0971e71 user: drh tags: trunk
14:25
Add a test to ensure that the app-defined pcache xFetch() method is never passed a key of zero. check-in: 0bdbe49c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/func.c.

   200    200     if( typeHaystack==SQLITE_NULL || typeNeedle==SQLITE_NULL ) return;
   201    201     nHaystack = sqlite3_value_bytes(argv[0]);
   202    202     nNeedle = sqlite3_value_bytes(argv[1]);
   203    203     if( nNeedle>0 ){
   204    204       if( typeHaystack==SQLITE_BLOB && typeNeedle==SQLITE_BLOB ){
   205    205         zHaystack = sqlite3_value_blob(argv[0]);
   206    206         zNeedle = sqlite3_value_blob(argv[1]);
          207  +      assert( zNeedle!=0 );
          208  +      assert( zHaystack!=0 || nHaystack==0 );
   207    209         isText = 0;
   208    210       }else{
   209    211         zHaystack = sqlite3_value_text(argv[0]);
   210    212         zNeedle = sqlite3_value_text(argv[1]);
   211    213         isText = 1;
   212         -      if( zNeedle==0 ) return;
   213         -      assert( zHaystack );
          214  +      if( zHaystack==0 || zNeedle==0 ) return;
   214    215       }
   215    216       while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){
   216    217         N++;
   217    218         do{
   218    219           nHaystack--;
   219    220           zHaystack++;
   220    221         }while( isText && (zHaystack[0]&0xc0)==0x80 );