/ Check-in [3ea2bad2]
Login

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

Overview
Comment:Fix a case where NULL was being passed to memcmp() following an OOM. This is probably not a real problem, as the number-of-bytes parameter was passed 0 in this case, but it was causing a santizer complaint.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:3ea2bad27e516d5dbfa4a9cb0c767d6a8387280a7e4bbf2ae80cd318da670d66
User & Date: dan 2017-05-22 08:04:09
Context
2017-05-22
14:04
Merge the last-minute 3.19.0 changes into trunk. check-in: e6ba2a93 user: drh tags: trunk
08:04
Fix a case where NULL was being passed to memcmp() following an OOM. This is probably not a real problem, as the number-of-bytes parameter was passed 0 in this case, but it was causing a santizer complaint. check-in: 3ea2bad2 user: dan tags: trunk
00:45
When planning a query using sorting, resolve ties in the solver by selecting loop plans with the smaller unsorted cost. check-in: f261678c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

   863    863     int nKey2, const void *pKey2
   864    864   ){
   865    865     int rc, n;
   866    866     n = nKey1<nKey2 ? nKey1 : nKey2;
   867    867     /* EVIDENCE-OF: R-65033-28449 The built-in BINARY collation compares
   868    868     ** strings byte by byte using the memcmp() function from the standard C
   869    869     ** library. */
          870  +  assert( pKey1 && pKey2 );
   870    871     rc = memcmp(pKey1, pKey2, n);
   871    872     if( rc==0 ){
   872    873       if( padFlag
   873    874        && allSpaces(((char*)pKey1)+n, nKey1-n)
   874    875        && allSpaces(((char*)pKey2)+n, nKey2-n)
   875    876       ){
   876    877         /* EVIDENCE-OF: R-31624-24737 RTRIM is like BINARY except that extra

Changes to src/vdbeaux.c.

  3727   3727     if( pMem1->enc==pColl->enc ){
  3728   3728       /* The strings are already in the correct encoding.  Call the
  3729   3729        ** comparison function directly */
  3730   3730       return pColl->xCmp(pColl->pUser,pMem1->n,pMem1->z,pMem2->n,pMem2->z);
  3731   3731     }else{
  3732   3732       int rc;
  3733   3733       const void *v1, *v2;
  3734         -    int n1, n2;
  3735   3734       Mem c1;
  3736   3735       Mem c2;
  3737   3736       sqlite3VdbeMemInit(&c1, pMem1->db, MEM_Null);
  3738   3737       sqlite3VdbeMemInit(&c2, pMem1->db, MEM_Null);
  3739   3738       sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
  3740   3739       sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
  3741   3740       v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
  3742         -    n1 = v1==0 ? 0 : c1.n;
  3743   3741       v2 = sqlite3ValueText((sqlite3_value*)&c2, pColl->enc);
  3744         -    n2 = v2==0 ? 0 : c2.n;
  3745         -    rc = pColl->xCmp(pColl->pUser, n1, v1, n2, v2);
  3746         -    if( (v1==0 || v2==0) && prcErr ) *prcErr = SQLITE_NOMEM_BKPT;
         3742  +    if( (v1==0 || v2==0) ){
         3743  +      if( prcErr ) *prcErr = SQLITE_NOMEM_BKPT;
         3744  +      rc = 0;
         3745  +    }else{
         3746  +      rc = pColl->xCmp(pColl->pUser, c1.n, v1, c2.n, v2);
         3747  +    }
  3747   3748       sqlite3VdbeMemRelease(&c1);
  3748   3749       sqlite3VdbeMemRelease(&c2);
  3749   3750       return rc;
  3750   3751     }
  3751   3752   }
  3752   3753   
  3753   3754   /*