/ Check-in [d9bc1c7f]
Login

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

Overview
Comment:Return a suitable error message if the mode= argument to a URI specifies a higher mode than what is allowed by context. Other minor cleanups for the URI parsing logic.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d9bc1c7fe0ca5f6973a85827330958f4d09f8171
User & Date: drh 2011-05-09 19:20:17
Context
2011-05-10
17:31
Add experimental support for read-only connections to WAL databases. check-in: bb59f986 user: dan tags: wal-readonly
10:17
Add new documentation keywords to the sqlite3_vfs description. check-in: ad3389a9 user: drh tags: trunk
2011-05-09
19:20
Return a suitable error message if the mode= argument to a URI specifies a higher mode than what is allowed by context. Other minor cleanups for the URI parsing logic. check-in: d9bc1c7f user: drh tags: trunk
2011-05-07
18:40
Set the sqlite3.mallocFailed flag if sqlite3ParseUri fails with SQLITE_NOMEM. check-in: ca3797d4 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

  1822   1822     char **pzFile,                  /* OUT: Filename component of URI */
  1823   1823     char **pzErrMsg                 /* OUT: Error message (if rc!=SQLITE_OK) */
  1824   1824   ){
  1825   1825     int rc = SQLITE_OK;
  1826   1826     unsigned int flags = *pFlags;
  1827   1827     const char *zVfs = zDefaultVfs;
  1828   1828     char *zFile;
         1829  +  char c;
  1829   1830     int nUri = sqlite3Strlen30(zUri);
  1830   1831   
  1831   1832     assert( *pzErrMsg==0 );
  1832   1833   
  1833   1834     if( ((flags & SQLITE_OPEN_URI) || sqlite3GlobalConfig.bOpenUri) 
  1834   1835      && nUri>=5 && memcmp(zUri, "file:", 5)==0 
  1835   1836     ){
................................................................................
  1869   1870       ** on the parsing context. As follows:
  1870   1871       **
  1871   1872       **   0: Parsing file-name.
  1872   1873       **   1: Parsing name section of a name=value query parameter.
  1873   1874       **   2: Parsing value section of a name=value query parameter.
  1874   1875       */
  1875   1876       eState = 0;
  1876         -    while( zUri[iIn] && zUri[iIn]!='#' ){
  1877         -      char c = zUri[iIn++];
         1877  +    while( (c = zUri[iIn])!=0 && c!='#' ){
         1878  +      iIn++;
  1878   1879         if( c=='%' 
  1879   1880          && sqlite3Isxdigit(zUri[iIn]) 
  1880   1881          && sqlite3Isxdigit(zUri[iIn+1]) 
  1881   1882         ){
  1882   1883           int octet = (sqlite3HexToInt(zUri[iIn++]) << 4);
  1883   1884           octet += sqlite3HexToInt(zUri[iIn++]);
  1884   1885   
  1885   1886           assert( octet>=0 && octet<256 );
  1886   1887           if( octet==0 ){
  1887   1888             /* This branch is taken when "%00" appears within the URI. In this
  1888   1889             ** case we ignore all text in the remainder of the path, name or
  1889   1890             ** value currently being parsed. So ignore the current character
  1890   1891             ** and skip to the next "?", "=" or "&", as appropriate. */
  1891         -          while( zUri[iIn] && zUri[iIn]!='#' 
  1892         -              && (eState!=0 || zUri[iIn]!='?')
  1893         -              && (eState!=1 || (zUri[iIn]!='=' && zUri[iIn]!='&'))
  1894         -              && (eState!=2 || zUri[iIn]!='&')
         1892  +          while( (c = zUri[iIn])!=0 && c!='#' 
         1893  +              && (eState!=0 || c!='?')
         1894  +              && (eState!=1 || (c!='=' && c!='&'))
         1895  +              && (eState!=2 || c!='&')
  1895   1896             ){
  1896   1897               iIn++;
  1897   1898             }
  1898   1899             continue;
  1899   1900           }
  1900   1901           c = octet;
  1901   1902         }else if( eState==1 && (c=='&' || c=='=') ){
................................................................................
  1979   1980             }
  1980   1981             if( mode==0 ){
  1981   1982               *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal);
  1982   1983               rc = SQLITE_ERROR;
  1983   1984               goto parse_uri_out;
  1984   1985             }
  1985   1986             if( mode>limit ){
         1987  +            *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s",
         1988  +                                        zModeType, zVal);
  1986   1989               rc = SQLITE_PERM;
  1987   1990               goto parse_uri_out;
  1988   1991             }
  1989   1992             flags = (flags & ~mask) | mode;
  1990   1993           }
  1991   1994         }
  1992   1995