/ Check-in [92ab1f72]
Login

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

Overview
Comment:Invoke the SQLITE_READ authorizer callback with a NULL column name for any table referenced by a query but from when no columns are extracted.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 92ab1f7257d2866c69eaaf4cf85990677b911ef425e9c5a36a96978cccfb551c
User & Date: drh 2017-05-10 16:12:00
Context
2017-05-10
16:33
Improved documentation for the SQLITE_READ authorizer callback. No code changes. check-in: 92c5ea70 user: drh tags: trunk
16:12
Invoke the SQLITE_READ authorizer callback with a NULL column name for any table referenced by a query but from when no columns are extracted. check-in: 92ab1f72 user: drh tags: trunk
13:36
Fix a couple of test scripts so that they work with -DSQLITE_DISABLE_FTS4_DEFERRED builds. check-in: 30018d31 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

  5111   5111       SELECTTRACE(1,pParse,p,("end compound-select processing\n"));
  5112   5112       pParse->nSelectIndent--;
  5113   5113   #endif
  5114   5114       return rc;
  5115   5115     }
  5116   5116   #endif
  5117   5117   
  5118         -  /* Generate code for all sub-queries in the FROM clause
         5118  +  /* For each term in the FROM clause, do two things:
         5119  +  ** (1) Authorized unreferenced tables
         5120  +  ** (2) Generate code for all sub-queries
  5119   5121     */
  5120         -#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
  5121   5122     for(i=0; i<pTabList->nSrc; i++){
  5122   5123       struct SrcList_item *pItem = &pTabList->a[i];
  5123   5124       SelectDest dest;
  5124         -    Select *pSub = pItem->pSelect;
         5125  +    Select *pSub;
         5126  +
         5127  +    /* Issue SQLITE_READ authorizations with a NULL column name for any tables that
         5128  +    ** are referenced but from which no values are extracted. Examples of where these
         5129  +    ** kinds of null SQLITE_READ authorizations would occur:
         5130  +    **
         5131  +    **     SELECT count(*) FROM t1;   -- SQLITE_READ t1 null
         5132  +    **     SELECT t1.* FROM t1, t2;   -- SQLITE_READ t2 null
         5133  +    */
         5134  +    if( pItem->colUsed==0 ){
         5135  +      sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, pItem->zDatabase, 0);
         5136  +    }
         5137  +
         5138  +#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
         5139  +    /* Generate code for all sub-queries in the FROM clause
         5140  +    */
         5141  +    pSub = pItem->pSelect;
  5125   5142       if( pSub==0 ) continue;
  5126   5143   
  5127   5144       /* Sometimes the code for a subquery will be generated more than
  5128   5145       ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
  5129   5146       ** for example.  In that case, do not regenerate the code to manifest
  5130   5147       ** a view or the co-routine to implement a view.  The first instance
  5131   5148       ** is sufficient, though the subroutine to manifest the view does need
................................................................................
  5238   5255         retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
  5239   5256         VdbeComment((v, "end %s", pItem->pTab->zName));
  5240   5257         sqlite3VdbeChangeP1(v, topAddr, retAddr);
  5241   5258         sqlite3ClearTempRegCache(pParse);
  5242   5259       }
  5243   5260       if( db->mallocFailed ) goto select_end;
  5244   5261       pParse->nHeight -= sqlite3SelectExprHeight(p);
  5245         -  }
  5246   5262   #endif
         5263  +  }
  5247   5264   
  5248   5265     /* Various elements of the SELECT copied into local variables for
  5249   5266     ** convenience */
  5250   5267     pEList = p->pEList;
  5251   5268     pWhere = p->pWhere;
  5252   5269     pGroupBy = p->pGroupBy;
  5253   5270     pHaving = p->pHaving;

Changes to test/auth.test.

  2474   2474     set ::authargs
  2475   2475   } [list                          \
  2476   2476     SQLITE_SELECT {} {} {} {}      \
  2477   2477     SQLITE_READ t7 a main {}       \
  2478   2478     SQLITE_READ t7 c main {}       \
  2479   2479   ]
  2480   2480   
         2481  +# If a table is referenced but no columns are read from the table,
         2482  +# that causes a single SQLITE_READ authorization with a NULL column
         2483  +# name.
         2484  +#
         2485  +set ::authargs [list]
         2486  +do_test auth-8.1 {
         2487  +  execsql {SELECT count(*) FROM t7}
         2488  +  set ::authargs
         2489  +} [list \
         2490  +  SQLITE_SELECT {} {} {} {}          \
         2491  +  SQLITE_FUNCTION {} count {} {}     \
         2492  +  SQLITE_READ t7 {} {} {}            \
         2493  +  ]
         2494  +set ::authargs [list]
         2495  +
         2496  +do_test auth-8.2 {
         2497  +  execsql {SELECT t6.a FROM t6, t7}
         2498  +  set ::authargs
         2499  +} [list \
         2500  +  SQLITE_SELECT {} {} {} {}          \
         2501  +  SQLITE_READ t6 a main {}           \
         2502  +  SQLITE_READ t7 {} {} {}            \
         2503  +  ]
  2481   2504   
  2482   2505   rename proc {}
  2483   2506   rename proc_real proc
  2484   2507   finish_test