/ Check-in [99222bb3]
Login

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

Overview
Comment:Merge latest trunk changes with this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | vtab-like-operator
Files: files | file ages | folders
SHA1: 99222bb3e5f9b2a9a10d9561a9fd8c0f717baaff
User & Date: dan 2015-11-24 17:44:26
Context
2015-11-24
18:04
Fix harmless compiler warnings in the TCL test harness logic. check-in: 2fba7a96 user: drh tags: vtab-like-operator
17:44
Merge latest trunk changes with this branch. check-in: 99222bb3 user: dan tags: vtab-like-operator
17:39
Add further tests and related fixes for GLOB/REGEXP/LIKE support in virtual tables. check-in: c5e9fd0d user: dan tags: vtab-like-operator
16:40
Remove from os_unix.c pointless logic that tries to prevent a recurrence of a warning message that can only occur once. check-in: 20256177 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  3814   3814         return 1;
  3815   3815       }
  3816   3816       if( pB->op==TK_COLLATE && sqlite3ExprCompare(pA, pB->pLeft, iTab)<2 ){
  3817   3817         return 1;
  3818   3818       }
  3819   3819       return 2;
  3820   3820     }
  3821         -  if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken ){
         3821  +  if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){
  3822   3822       if( pA->op==TK_FUNCTION ){
  3823   3823         if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2;
  3824   3824       }else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
  3825   3825         return pA->op==TK_COLLATE ? 1 : 2;
  3826   3826       }
  3827   3827     }
  3828   3828     if( (pA->flags & EP_Distinct)!=(pB->flags & EP_Distinct) ) return 2;

Changes to src/os_unix.c.

   254    254   #else
   255    255   # define UNIXFILE_DIRSYNC    0x00
   256    256   #endif
   257    257   #define UNIXFILE_PSOW        0x10     /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
   258    258   #define UNIXFILE_DELETE      0x20     /* Delete on close */
   259    259   #define UNIXFILE_URI         0x40     /* Filename might have query parameters */
   260    260   #define UNIXFILE_NOLOCK      0x80     /* Do no file locking */
   261         -#define UNIXFILE_WARNED    0x0100     /* verifyDbFile() warnings issued */
   262         -#define UNIXFILE_BLOCK     0x0200     /* Next SHM lock might block */
          261  +#define UNIXFILE_BLOCK     0x0100     /* Next SHM lock might block */
   263    262   
   264    263   /*
   265    264   ** Include code that is common to all os_*.c files
   266    265   */
   267    266   #include "os_common.h"
   268    267   
   269    268   /*
................................................................................
   320    319   ** The safest way to deal with the problem is to always use this wrapper
   321    320   ** which always has the same well-defined interface.
   322    321   */
   323    322   static int posixOpen(const char *zFile, int flags, int mode){
   324    323     return open(zFile, flags, mode);
   325    324   }
   326    325   
   327         -/*
   328         -** On some systems, calls to fchown() will trigger a message in a security
   329         -** log if they come from non-root processes.  So avoid calling fchown() if
   330         -** we are not running as root.
   331         -*/
   332         -static int posixFchown(int fd, uid_t uid, gid_t gid){
   333         -#if OS_VXWORKS
   334         -  return 0;
   335         -#else
   336         -  return geteuid() ? 0 : fchown(fd,uid,gid);
   337         -#endif
   338         -}
   339         -
   340    326   /* Forward reference */
   341    327   static int openDirectory(const char*, int*);
   342    328   static int unixGetpagesize(void);
   343    329   
   344    330   /*
   345    331   ** Many system calls are accessed through pointer-to-functions so that
   346    332   ** they may be overridden at runtime to facilitate fault injection during
................................................................................
   419    405     { "pwrite64",     (sqlite3_syscall_ptr)pwrite64,   0  },
   420    406   #else
   421    407     { "pwrite64",     (sqlite3_syscall_ptr)0,          0  },
   422    408   #endif
   423    409   #define osPwrite64  ((ssize_t(*)(int,const void*,size_t,off_t))\
   424    410                       aSyscall[13].pCurrent)
   425    411   
   426         -  { "fchmod",       (sqlite3_syscall_ptr)fchmod,     0  },
          412  +  { "fchmod",       (sqlite3_syscall_ptr)fchmod,          0  },
   427    413   #define osFchmod    ((int(*)(int,mode_t))aSyscall[14].pCurrent)
   428    414   
   429    415   #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
   430    416     { "fallocate",    (sqlite3_syscall_ptr)posix_fallocate,  0 },
   431    417   #else
   432    418     { "fallocate",    (sqlite3_syscall_ptr)0,                0 },
   433    419   #endif
................................................................................
   441    427   
   442    428     { "mkdir",        (sqlite3_syscall_ptr)mkdir,           0 },
   443    429   #define osMkdir     ((int(*)(const char*,mode_t))aSyscall[18].pCurrent)
   444    430   
   445    431     { "rmdir",        (sqlite3_syscall_ptr)rmdir,           0 },
   446    432   #define osRmdir     ((int(*)(const char*))aSyscall[19].pCurrent)
   447    433   
   448         -  { "fchown",       (sqlite3_syscall_ptr)posixFchown,     0 },
          434  +  { "fchown",       (sqlite3_syscall_ptr)fchown,          0 },
   449    435   #define osFchown    ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
          436  +
          437  +  { "geteuid",      (sqlite3_syscall_ptr)geteuid,         0 },
          438  +#define osGeteuid   ((uid_t(*)(void))aSyscall[21].pCurrent)
   450    439   
   451    440   #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
   452    441     { "mmap",       (sqlite3_syscall_ptr)mmap,     0 },
   453         -#define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[21].pCurrent)
          442  +#define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[22].pCurrent)
   454    443   
   455    444     { "munmap",       (sqlite3_syscall_ptr)munmap,          0 },
   456         -#define osMunmap ((void*(*)(void*,size_t))aSyscall[22].pCurrent)
          445  +#define osMunmap ((void*(*)(void*,size_t))aSyscall[23].pCurrent)
   457    446   
   458    447   #if HAVE_MREMAP
   459    448     { "mremap",       (sqlite3_syscall_ptr)mremap,          0 },
   460    449   #else
   461    450     { "mremap",       (sqlite3_syscall_ptr)0,               0 },
   462    451   #endif
   463         -#define osMremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[23].pCurrent)
          452  +#define osMremap ((void*(*)(void*,size_t,size_t,int,...))aSyscall[24].pCurrent)
          453  +
   464    454     { "getpagesize",  (sqlite3_syscall_ptr)unixGetpagesize, 0 },
   465         -#define osGetpagesize ((int(*)(void))aSyscall[24].pCurrent)
          455  +#define osGetpagesize ((int(*)(void))aSyscall[25].pCurrent)
   466    456   
   467    457     { "readlink",     (sqlite3_syscall_ptr)readlink,        0 },
   468         -#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[25].pCurrent)
          458  +#define osReadlink ((ssize_t(*)(const char*,char*,size_t))aSyscall[26].pCurrent)
   469    459   
   470    460   #endif
   471    461   
   472    462   }; /* End of the overrideable system calls */
   473    463   
          464  +
          465  +/*
          466  +** On some systems, calls to fchown() will trigger a message in a security
          467  +** log if they come from non-root processes.  So avoid calling fchown() if
          468  +** we are not running as root.
          469  +*/
          470  +static int robustFchown(int fd, uid_t uid, gid_t gid){
          471  +#if OS_VXWORKS
          472  +  return 0;
          473  +#else
          474  +  return osGeteuid() ? 0 : osFchown(fd,uid,gid);
          475  +#endif
          476  +}
          477  +
   474    478   /*
   475    479   ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
   476    480   ** "unix" VFSes.  Return SQLITE_OK opon successfully updating the
   477    481   ** system call pointer, or SQLITE_NOTFOUND if there is no configurable
   478    482   ** system call named zName.
   479    483   */
   480    484   static int unixSetSystemCall(
................................................................................
  1095   1099   /*
  1096   1100   ** A lists of all unixInodeInfo objects.
  1097   1101   */
  1098   1102   static unixInodeInfo *inodeList = 0;
  1099   1103   
  1100   1104   /*
  1101   1105   **
  1102         -** This function - unixLogError_x(), is only ever called via the macro
         1106  +** This function - unixLogErrorAtLine(), is only ever called via the macro
  1103   1107   ** unixLogError().
  1104   1108   **
  1105   1109   ** It is invoked after an error occurs in an OS function and errno has been
  1106   1110   ** set. It logs a message using sqlite3_log() containing the current value of
  1107   1111   ** errno and, if possible, the human-readable equivalent from strerror() or
  1108   1112   ** strerror_r().
  1109   1113   **
................................................................................
  1351   1355   ** (3) The file has not been renamed or unlinked
  1352   1356   **
  1353   1357   ** Issue sqlite3_log(SQLITE_WARNING,...) messages if anything is not right.
  1354   1358   */
  1355   1359   static void verifyDbFile(unixFile *pFile){
  1356   1360     struct stat buf;
  1357   1361     int rc;
  1358         -  if( pFile->ctrlFlags & UNIXFILE_WARNED ){
  1359         -    /* One or more of the following warnings have already been issued.  Do not
  1360         -    ** repeat them so as not to clutter the error log */
  1361         -    return;
  1362         -  }
  1363   1362     rc = osFstat(pFile->h, &buf);
  1364   1363     if( rc!=0 ){
  1365   1364       sqlite3_log(SQLITE_WARNING, "cannot fstat db file %s", pFile->zPath);
  1366         -    pFile->ctrlFlags |= UNIXFILE_WARNED;
  1367   1365       return;
  1368   1366     }
  1369   1367     if( buf.st_nlink==0 && (pFile->ctrlFlags & UNIXFILE_DELETE)==0 ){
  1370   1368       sqlite3_log(SQLITE_WARNING, "file unlinked while open: %s", pFile->zPath);
  1371         -    pFile->ctrlFlags |= UNIXFILE_WARNED;
  1372   1369       return;
  1373   1370     }
  1374   1371     if( buf.st_nlink>1 ){
  1375   1372       sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath);
  1376         -    pFile->ctrlFlags |= UNIXFILE_WARNED;
  1377   1373       return;
  1378   1374     }
  1379   1375     if( fileHasMoved(pFile) ){
  1380   1376       sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath);
  1381         -    pFile->ctrlFlags |= UNIXFILE_WARNED;
  1382   1377       return;
  1383   1378     }
  1384   1379   }
  1385   1380   
  1386   1381   
  1387   1382   /*
  1388   1383   ** This routine checks if there is a RESERVED lock held on the specified
................................................................................
  4339   4334           goto shm_open_err;
  4340   4335         }
  4341   4336   
  4342   4337         /* If this process is running as root, make sure that the SHM file
  4343   4338         ** is owned by the same user that owns the original database.  Otherwise,
  4344   4339         ** the original owner will not be able to connect.
  4345   4340         */
  4346         -      osFchown(pShmNode->h, sStat.st_uid, sStat.st_gid);
         4341  +      robustFchown(pShmNode->h, sStat.st_uid, sStat.st_gid);
  4347   4342     
  4348   4343         /* Check to see if another process is holding the dead-man switch.
  4349   4344         ** If not, truncate the file to zero length. 
  4350   4345         */
  4351   4346         rc = SQLITE_OK;
  4352   4347         if( unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1)==SQLITE_OK ){
  4353   4348           if( robust_ftruncate(pShmNode->h, 0) ){
................................................................................
  5823   5818       }
  5824   5819   
  5825   5820       /* If this process is running as root and if creating a new rollback
  5826   5821       ** journal or WAL file, set the ownership of the journal or WAL to be
  5827   5822       ** the same as the original database.
  5828   5823       */
  5829   5824       if( flags & (SQLITE_OPEN_WAL|SQLITE_OPEN_MAIN_JOURNAL) ){
  5830         -      osFchown(fd, uid, gid);
         5825  +      robustFchown(fd, uid, gid);
  5831   5826       }
  5832   5827     }
  5833   5828     assert( fd>=0 );
  5834   5829     if( pOutFlags ){
  5835   5830       *pOutFlags = flags;
  5836   5831     }
  5837   5832   
................................................................................
  7580   7575       UNIXVFS("unix-proxy",    proxyIoFinder ),
  7581   7576   #endif
  7582   7577     };
  7583   7578     unsigned int i;          /* Loop counter */
  7584   7579   
  7585   7580     /* Double-check that the aSyscall[] array has been constructed
  7586   7581     ** correctly.  See ticket [bb3a86e890c8e96ab] */
  7587         -  assert( ArraySize(aSyscall)==26 );
         7582  +  assert( ArraySize(aSyscall)==27 );
  7588   7583   
  7589   7584     /* Register all VFSes defined in the aVfs[] array */
  7590   7585     for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
  7591   7586       sqlite3_vfs_register(&aVfs[i], i==0);
  7592   7587     }
  7593   7588     return SQLITE_OK; 
  7594   7589   }

Changes to src/test8.c.

   844    844           case SQLITE_INDEX_CONSTRAINT_GT:
   845    845             zOp = ">"; break;
   846    846           case SQLITE_INDEX_CONSTRAINT_LE:
   847    847             zOp = "<="; break;
   848    848           case SQLITE_INDEX_CONSTRAINT_GE:
   849    849             zOp = ">="; break;
   850    850           case SQLITE_INDEX_CONSTRAINT_MATCH:
          851  +          /* Purposely translate the MATCH operator into a LIKE, which
          852  +          ** will be used by the next block of code to construct a new
          853  +          ** query.  It should also be noted here that the next block
          854  +          ** of code requires the first letter of this operator to be
          855  +          ** in upper-case to trigger the special MATCH handling (i.e.
          856  +          ** wrapping the bound parameter with literal '%'s).
          857  +          */
   851    858             zOp = "LIKE"; break;
   852    859           case SQLITE_INDEX_CONSTRAINT_LIKE:
   853    860             zOp = "like"; break;
   854    861           case SQLITE_INDEX_CONSTRAINT_GLOB:
   855    862             zOp = "glob"; break;
   856    863           case SQLITE_INDEX_CONSTRAINT_REGEXP:
   857    864             zOp = "regexp"; break;

Changes to src/vdbeaux.c.

   833    833   void sqlite3VdbeChangeToNoop(Vdbe *p, int addr){
   834    834     if( addr<p->nOp ){
   835    835       VdbeOp *pOp = &p->aOp[addr];
   836    836       sqlite3 *db = p->db;
   837    837       freeP4(db, pOp->p4type, pOp->p4.p);
   838    838       memset(pOp, 0, sizeof(pOp[0]));
   839    839       pOp->opcode = OP_Noop;
   840         -    if( addr==p->nOp-1 ) p->nOp--;
   841    840     }
   842    841   }
   843    842   
   844    843   /*
   845    844   ** If the last opcode is "op" and it is not a jump destination,
   846    845   ** then remove it.  Return true if and only if an opcode was removed.
   847    846   */

Changes to test/distinct.test.

   247    247   } {1 2 3 4 5 6}
   248    248   do_execsql_test 5.5 {
   249    249     SELECT DISTINCT x FROM t1 ORDER BY x DESC;
   250    250   } {6 5 4 3 2 1}
   251    251   do_execsql_test 5.6 {
   252    252     SELECT DISTINCT x FROM t1 ORDER BY x;
   253    253   } {1 2 3 4 5 6}
          254  +
          255  +#-------------------------------------------------------------------------
          256  +# 2015-11-23.  Problem discovered by Kostya Serebryany using libFuzzer
          257  +#
          258  +db close
          259  +sqlite3 db :memory:
          260  +do_execsql_test 6.1 {
          261  +  CREATE TABLE jjj(x);
          262  +  SELECT (SELECT 'mmm' UNION SELECT DISTINCT max(name) ORDER BY 1) 
          263  +    FROM sqlite_master;
          264  +} {jjj}
          265  +do_execsql_test 6.2 {
          266  +  CREATE TABLE nnn(x);
          267  +  SELECT (SELECT 'mmm' UNION SELECT DISTINCT max(name) ORDER BY 1) 
          268  +    FROM sqlite_master;
          269  +} {mmm}
          270  +
   254    271   
   255    272   finish_test

Changes to test/hexlit.test.

   105    105   } {0}
   106    106   
   107    107   # Oversized hex literals are rejected
   108    108   #
   109    109   do_catchsql_test hexlist-400 {
   110    110     SELECT 0x10000000000000000;
   111    111   } {1 {hex literal too big: 0x10000000000000000}}
          112  +do_catchsql_test hexlist-401 {
          113  +  SELECT DISTINCT 0x10000000000000000;
          114  +} {1 {hex literal too big: 0x10000000000000000}}
   112    115   do_catchsql_test hexlist-410 {
   113    116     DROP TABLE IF EXISTS t1;
   114    117     CREATE TABLE t1(x);
   115    118     INSERT INTO t1 VALUES(1+0x10000000000000000);
   116    119   } {1 {hex literal too big: 0x10000000000000000}}
   117    120   
   118    121   
   119    122   finish_test

Changes to test/syscall.test.

    56     56   #-------------------------------------------------------------------------
    57     57   # Tests for the xNextSystemCall method.
    58     58   #
    59     59   foreach s {
    60     60       open close access getcwd stat fstat ftruncate
    61     61       fcntl read pread write pwrite fchmod fallocate
    62     62       pread64 pwrite64 unlink openDirectory mkdir rmdir 
    63         -    statvfs fchown umask mmap munmap mremap
           63  +    statvfs fchown geteuid umask mmap munmap mremap
    64     64       getpagesize readlink
    65     65   } {
    66     66     if {[test_syscall exists $s]} {lappend syscall_list $s}
    67     67   }
    68     68   do_test 3.1 { lsort [test_syscall list] } [lsort $syscall_list]
    69     69   
    70     70   #-------------------------------------------------------------------------