/ Check-in [572de7e4]
Login

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

Overview
Comment:Fix an invalid pointer comparison triggered by renaming a table column when there are views with explicit column names in the schema.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 572de7e4e33562c72cd90790b267ba389370f21ddcaebc4db609fd76ae9b7ada
User & Date: dan 2018-09-12 08:51:48
Context
2018-09-12
14:28
Improvements to the documentation for SQLITE_FCNTL_DATA_VERSION. No changes to code. check-in: 27837624 user: drh tags: trunk
08:51
Fix an invalid pointer comparison triggered by renaming a table column when there are views with explicit column names in the schema. check-in: 572de7e4 user: dan tags: trunk
01:05
Fix some harmless compiler warnings seen with MSVC. check-in: 78862252 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   718    718   void sqlite3RenameExprUnmap(Parse *pParse, Expr *pExpr){
   719    719     Walker sWalker;
   720    720     memset(&sWalker, 0, sizeof(Walker));
   721    721     sWalker.pParse = pParse;
   722    722     sWalker.xExprCallback = renameUnmapExprCb;
   723    723     sqlite3WalkExpr(&sWalker, pExpr);
   724    724   }
          725  +
          726  +/*
          727  +** Remove all nodes that are part of expression-list pEList from the 
          728  +** rename list.
          729  +*/
          730  +void sqlite3RenameExprlistUnmap(Parse *pParse, ExprList *pEList){
          731  +  if( pEList ){
          732  +    int i;
          733  +    Walker sWalker;
          734  +    memset(&sWalker, 0, sizeof(Walker));
          735  +    sWalker.pParse = pParse;
          736  +    sWalker.xExprCallback = renameUnmapExprCb;
          737  +    sqlite3WalkExprList(&sWalker, pEList);
          738  +    for(i=0; i<pEList->nExpr; i++){
          739  +      sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zName);
          740  +    }
          741  +  }
          742  +}
   725    743   
   726    744   /*
   727    745   ** Free the list of RenameToken objects given in the second argument
   728    746   */
   729    747   static void renameTokenFree(sqlite3 *db, RenameToken *pToken){
   730    748     RenameToken *pNext;
   731    749     RenameToken *p;

Changes to src/build.c.

  2207   2207     sEnd.n = 1;
  2208   2208   
  2209   2209     /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
  2210   2210     sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
  2211   2211   
  2212   2212   create_view_fail:
  2213   2213     sqlite3SelectDelete(db, pSelect);
         2214  +  if( IN_RENAME_OBJECT ){
         2215  +    sqlite3RenameExprlistUnmap(pParse, pCNames);
         2216  +  }
  2214   2217     sqlite3ExprListDelete(db, pCNames);
  2215   2218     return;
  2216   2219   }
  2217   2220   #endif /* SQLITE_OMIT_VIEW */
  2218   2221   
  2219   2222   #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_VIRTUALTABLE)
  2220   2223   /*

Changes to src/sqliteInt.h.

  4238   4238   int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
  4239   4239   void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
  4240   4240   void sqlite3AlterFinishAddColumn(Parse *, Token *);
  4241   4241   void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
  4242   4242   void *sqlite3RenameTokenMap(Parse*, void*, Token*);
  4243   4243   void sqlite3RenameTokenRemap(Parse*, void *pTo, void *pFrom);
  4244   4244   void sqlite3RenameExprUnmap(Parse*, Expr*);
         4245  +void sqlite3RenameExprlistUnmap(Parse*, ExprList*);
  4245   4246   CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*);
  4246   4247   char sqlite3AffinityType(const char*, Column*);
  4247   4248   void sqlite3Analyze(Parse*, Token*, Token*);
  4248   4249   int sqlite3InvokeBusyHandler(BusyHandler*, sqlite3_file*);
  4249   4250   int sqlite3FindDb(sqlite3*, Token*);
  4250   4251   int sqlite3FindDbName(sqlite3 *, const char *);
  4251   4252   int sqlite3AnalysisLoad(sqlite3*,int iDB);

Changes to test/altercol.test.

   748    748     INSERT INTO t1 VALUES(111);
   749    749     SELECT v FROM log;
   750    750   } {111}
   751    751   
   752    752   do_execsql_test 18.1 {
   753    753     ALTER TABLE t1 RENAME a TO b;
   754    754   }
          755  +
          756  +reset_db
          757  +do_execsql_test 19.0 {
          758  +  CREATE TABLE t1(a, b);
          759  +  CREATE TABLE t2(c, d);
          760  +  CREATE VIEW v2(e) AS SELECT coalesce(t2.c,t1.a) FROM t1, t2 WHERE t1.b=t2.d;
          761  +}
          762  +
          763  +do_execsql_test 19.1 {
          764  +  ALTER TABLE t1 RENAME a TO f;
          765  +  SELECT sql FROM sqlite_master WHERE name = 'v2';
          766  +} {
          767  +  {CREATE VIEW v2(e) AS SELECT coalesce(t2.c,t1.f) FROM t1, t2 WHERE t1.b=t2.d}
          768  +}
          769  +
   755    770   
   756    771   
   757    772   finish_test