SQLite

Check-in [d09f8c36]
Login

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

Overview
Comment:Fix a case when a pointer might be used after being freed in the ALTER TABLE code. Fix for [4722bdab08cb1].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d09f8c3621d5f7f8c6d99d7d82bcaa8421855b3f470bea2b26c858106382b906
User & Date: dan 2020-04-03 11:20:40
Context
2020-04-03
13:29
Fix a case when a pointer might be used after being freed in the ALTER TABLE code. Fix for [4722bdab08cb1]. (check-in: 52f800fa user: drh tags: branch-3.31)
11:52
Do not suppress errors when resolving references in an ORDER BY clause belonging to a compound SELECT within a view or trigger within ALTER TABLE. Fix for ticket [a10a14e9b4ba2]. (check-in: 68429388 user: dan tags: trunk)
11:20
Fix a case when a pointer might be used after being freed in the ALTER TABLE code. Fix for [4722bdab08cb1]. (check-in: d09f8c36 user: dan tags: trunk)
2020-04-02
13:21
Fix an obsolete comment in the parameter binding logic of the CLI. No changes to code. (check-in: c9c735e2 user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/alter.c.

750
751
752
753
754
755
756















757
758
759
760
761
762
763
      sNC.pParse = pWalker->pParse;
      sqlite3SelectPrep(sNC.pParse, p, &sNC);
      sqlite3WalkSelect(pWalker, p);
      sqlite3RenameExprlistUnmap(pWalker->pParse, pWith->a[i].pCols);
    }
  }
}
















/*
** Walker callback used by sqlite3RenameExprUnmap().
*/
static int renameUnmapSelectCb(Walker *pWalker, Select *p){
  Parse *pParse = pWalker->pParse;
  int i;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
      sNC.pParse = pWalker->pParse;
      sqlite3SelectPrep(sNC.pParse, p, &sNC);
      sqlite3WalkSelect(pWalker, p);
      sqlite3RenameExprlistUnmap(pWalker->pParse, pWith->a[i].pCols);
    }
  }
}

/*
** Unmap all tokens in the IdList object passed as the second argument.
*/
static void unmapColumnIdlistNames(
  Parse *pParse,
  IdList *pIdList
){
  if( pIdList ){
    int ii;
    for(ii=0; ii<pIdList->nId; ii++){
      sqlite3RenameTokenRemap(pParse, 0, (void*)pIdList->a[ii].zName);
    }
  }
}

/*
** Walker callback used by sqlite3RenameExprUnmap().
*/
static int renameUnmapSelectCb(Walker *pWalker, Select *p){
  Parse *pParse = pWalker->pParse;
  int i;
772
773
774
775
776
777
778

779
780
781
782
783
784
785
    }
  }
  if( ALWAYS(p->pSrc) ){  /* Every Select as a SrcList, even if it is empty */
    SrcList *pSrc = p->pSrc;
    for(i=0; i<pSrc->nSrc; i++){
      sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
      if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort;

    }
  }

  renameWalkWith(pWalker, p);
  return WRC_Continue;
}








>







787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
    }
  }
  if( ALWAYS(p->pSrc) ){  /* Every Select as a SrcList, even if it is empty */
    SrcList *pSrc = p->pSrc;
    for(i=0; i<pSrc->nSrc; i++){
      sqlite3RenameTokenRemap(pParse, 0, (void*)pSrc->a[i].zName);
      if( sqlite3WalkExpr(pWalker, pSrc->a[i].pOn) ) return WRC_Abort;
      unmapColumnIdlistNames(pParse, pSrc->a[i].pUsing);
    }
  }

  renameWalkWith(pWalker, p);
  return WRC_Continue;
}

979
980
981
982
983
984
985

986
987
988
989
990
991
992
      char *zName = pIdList->a[i].zName;
      if( 0==sqlite3_stricmp(zName, zOld) ){
        renameTokenFind(pParse, pCtx, (void*)zName);
      }
    }
  }
}


/*
** Parse the SQL statement zSql using Parse object (*p). The Parse object
** is initialized by this function before it is used.
*/
static int renameParseSql(
  Parse *p,                       /* Memory to use for Parse object */







>







995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
      char *zName = pIdList->a[i].zName;
      if( 0==sqlite3_stricmp(zName, zOld) ){
        renameTokenFind(pParse, pCtx, (void*)zName);
      }
    }
  }
}


/*
** Parse the SQL statement zSql using Parse object (*p). The Parse object
** is initialized by this function before it is used.
*/
static int renameParseSql(
  Parse *p,                       /* Memory to use for Parse object */

Changes to test/altertab.test.

625
626
627
628
629
630
631











632
633
  INSERT INTO t3(x) VALUES(123);
  SELECT * FROM t2;
} {1}
do_execsql_test 19.120 {
  INSERT INTO t3(x) VALUES('xyz');
  SELECT * FROM t2;
} {1 1 1 1 1 1 1 1}












finish_test







>
>
>
>
>
>
>
>
>
>
>


625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
  INSERT INTO t3(x) VALUES(123);
  SELECT * FROM t2;
} {1}
do_execsql_test 19.120 {
  INSERT INTO t3(x) VALUES('xyz');
  SELECT * FROM t2;
} {1 1 1 1 1 1 1 1}

# Ticket 4722bdab08cb14
reset_db
do_execsql_test 20.0 {
  CREATE TABLE a(a);
  CREATE VIEW b AS SELECT(SELECT *FROM c JOIN a USING(d, a, a, a) JOIN a) IN();
}

do_execsql_test 20.1 {
  ALTER TABLE a RENAME a TO e;
} {}

finish_test