SQLite

Check-in [c4cb9708d4]
Login

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

Overview
Comment:Avoid a crash that could occur when a database containing a table with a temp trigger that has the same name as a temp table is detached.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c4cb9708d48ead10ee9543f86878be8382cd6e850950d5384c95254bac4a8d6e
User & Date: dan 2019-12-03 03:34:06.850
Context
2019-12-04
01:42
Fix a double-free that could occur when a component of a compound SELECT with an ORDER BY clause uses named window definitions. (check-in: 92893b7980 user: dan tags: trunk)
2019-12-03
03:34
Avoid a crash that could occur when a database containing a table with a temp trigger that has the same name as a temp table is detached. (check-in: c4cb9708d4 user: dan tags: trunk)
03:31
Avoid a harmless zero offset of a null pointer in FTS3, so as to not provoke unnecessary warnings from run-time checkers. (check-in: 85d95abec4 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/trigger.c.
658
659
660
661
662
663
664
665

666



667
668
669
670
671
672
673
  pHash = &(db->aDb[iDb].pSchema->trigHash);
  pTrigger = sqlite3HashInsert(pHash, zName, 0);
  if( ALWAYS(pTrigger) ){
    if( pTrigger->pSchema==pTrigger->pTabSchema ){
      Table *pTab = tableOfTrigger(pTrigger);
      if( pTab ){
        Trigger **pp;
        for(pp=&pTab->pTrigger; *pp!=pTrigger; pp=&((*pp)->pNext));

        *pp = (*pp)->pNext;



      }
    }
    sqlite3DeleteTrigger(db, pTrigger);
    db->mDbFlags |= DBFLAG_SchemaChange;
  }
}








|
>
|
>
>
>







658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
  pHash = &(db->aDb[iDb].pSchema->trigHash);
  pTrigger = sqlite3HashInsert(pHash, zName, 0);
  if( ALWAYS(pTrigger) ){
    if( pTrigger->pSchema==pTrigger->pTabSchema ){
      Table *pTab = tableOfTrigger(pTrigger);
      if( pTab ){
        Trigger **pp;
        for(pp=&pTab->pTrigger; *pp; pp=&((*pp)->pNext)){
          if( *pp==pTrigger ){
            *pp = (*pp)->pNext;
            break;
          }
        }
      }
    }
    sqlite3DeleteTrigger(db, pTrigger);
    db->mDbFlags |= DBFLAG_SchemaChange;
  }
}

Changes to test/attach4.test.
110
111
112
113
114
115
116
117



















118

    lappend L $name [execsql "SELECT x FROM $name.tbl"]
  }
  set L
} $files

db close
foreach {name f} $files { forcedelete $f }




















finish_test









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

>
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
    lappend L $name [execsql "SELECT x FROM $name.tbl"]
  }
  set L
} $files

db close
foreach {name f} $files { forcedelete $f }

#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
  ATTACH DATABASE '' AS aux;
  CREATE TABLE IF NOT EXISTS aux.t1(a, b);
  CREATE TEMPORARY TRIGGER tr1 DELETE ON t1 BEGIN 
    DELETE FROM t1; 
  END;
  CREATE TABLE temp.t1(a, b);
}

do_execsql_test 2.1 {
  DETACH DATABASE aux;
}

do_execsql_test 2.2 {
  DROP TRIGGER tr1;
}

finish_test