SQLite

Check-in [94225d69]
Login

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

Overview
Comment:If there are errors in a nested CTE, be sure to abandon processing. Do not continue since the parse tree may have been left in a goofy state which could cause use-after-free and segfaults. See forum post aa4a7a3980 for an example.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 94225d693932eb0b5d7799d40513afbd31ed40e1e156675eb92ad7216f1ff20f
User & Date: drh 2021-05-21 21:49:07
Context
2021-05-22
01:30
If an FTS5 Cursor fails to enlarge the space for the aInst array, set the size of the aInst array to zero. dbsqlfuzz 294254b8105cca409f27a711f1eb2e9e63cbcac5. (check-in: 4ae5e5b5 user: drh tags: trunk)
2021-05-21
21:49
If there are errors in a nested CTE, be sure to abandon processing. Do not continue since the parse tree may have been left in a goofy state which could cause use-after-free and segfaults. See forum post aa4a7a3980 for an example. (check-in: 94225d69 user: drh tags: trunk)
16:41
Fix a problem with SQLITE_MAX_MEMORY in malloc.c. (check-in: c18dbe2f user: dan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/select.c.

5062
5063
5064
5065
5066
5067
5068





5069
5070
5071
5072
5073
5074
5075
  Cte *pCte;               /* Matched CTE (or NULL if no match) */
  With *pWith;             /* The matching WITH */

  assert( pFrom->pTab==0 );
  if( pParse->pWith==0 ){
    /* There are no WITH clauses in the stack.  No match is possible */
    return 0;





  }
  if( pFrom->zDatabase!=0 ){
    /* The FROM term contains a schema qualifier (ex: main.t1) and so
    ** it cannot possibly be a CTE reference. */
    return 0;
  }
  if( pFrom->fg.notCte ){







>
>
>
>
>







5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
  Cte *pCte;               /* Matched CTE (or NULL if no match) */
  With *pWith;             /* The matching WITH */

  assert( pFrom->pTab==0 );
  if( pParse->pWith==0 ){
    /* There are no WITH clauses in the stack.  No match is possible */
    return 0;
  }
  if( pParse->nErr ){
    /* Prior errors might have left pParse->pWith in a goofy state, so
    ** go no further. */
    return 0;
  }
  if( pFrom->zDatabase!=0 ){
    /* The FROM term contains a schema qualifier (ex: main.t1) and so
    ** it cannot possibly be a CTE reference. */
    return 0;
  }
  if( pFrom->fg.notCte ){

Changes to test/with2.test.

544
545
546
547
548
549
550



















































551
552
    SELECT (
      WITH t1(a) AS (VALUES( c ))
      SELECT ( SELECT t1a.a FROM t1 AS t1a, t1 AS t1x )
      FROM t1 AS xyz GROUP BY 1
    )
  )
} {1}




















































finish_test







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


544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
    SELECT (
      WITH t1(a) AS (VALUES( c ))
      SELECT ( SELECT t1a.a FROM t1 AS t1a, t1 AS t1x )
      FROM t1 AS xyz GROUP BY 1
    )
  )
} {1}

# 2021-05-21
# Forum post https://sqlite.org/forum/forumpost/aa4a7a3980
#
reset_db
do_execsql_test 11.1 {
  CREATE TABLE t1(a);
  CREATE VIEW v2(c) AS
      WITH x AS (
        WITH y AS (
           WITH z AS(SELECT * FROM t1)
           SELECT * FROM v2
        ) SELECT a
      ) SELECT * from t1;
  ALTER TABLE t1 RENAME COLUMN a TO b;
  SELECT sql FROM sqlite_schema WHERE name='t1';
} {{CREATE TABLE t1(b)}}
do_catchsql_test 11.2 {
  INSERT INTO t1 VALUES(55);
  SELECT * FROM v2;
} {0 55}
do_catchsql_test 11.3 {
  DROP VIEW v2;
  CREATE VIEW v2(c) AS
      WITH x AS (
        WITH y AS (
           WITH z AS(SELECT * FROM t1)
           SELECT * FROM v2
        ) SELECT a
      ) SELECT * from t1, x;
  SELECT * FROM v2;
} {1 {no such column: a}}
do_catchsql_test 11.4 {
  DROP VIEW v2;
  CREATE VIEW v2(c) AS
      WITH x AS (
        WITH y AS (
           WITH z AS(SELECT * FROM t1)
           SELECT * FROM v2
        ) SELECT *
      ) SELECT * from t1, x;
  SELECT * FROM v2;
} {1 {no tables specified}}
do_catchsql_test 11.5 {
  WITH x AS (
    WITH y AS (
       WITH z AS(SELECT * FROM t1)
       SELECT * FROM no_such_table
    ) SELECT a
  ) SELECT * from t1;
} {0 55}

finish_test