]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Do not crash when a corrupt database contains two indices with the same name. (CVS...
authordanielk1977 <danielk1977@noemail.net>
Tue, 13 Mar 2007 16:32:25 +0000 (16:32 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Tue, 13 Mar 2007 16:32:25 +0000 (16:32 +0000)
FossilOrigin-Name: 48b2a40008a09881ed9da3548095495a3d4a6647

manifest
manifest.uuid
src/build.c
test/corrupt2.test

index 078368f6e0dce0cbe66e702803e56a0688bf7745..c40aabbeb78ba7eb494979d9a620a94e1918233c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Clarify\sthe\suse\sof\sloop\svariables\sin\sa\sexpr.c.\s(CVS\s3683)
-D 2007-03-12T23:48:53
+C Do\snot\scrash\swhen\sa\scorrupt\sdatabase\scontains\stwo\sindices\swith\sthe\ssame\sname.\s(CVS\s3684)
+D 2007-03-13T16:32:25
 F Makefile.in 1fe3d0b46e40fd684e1e61f8e8056cefed16de9f
 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -60,7 +60,7 @@ F src/attach.c b11eb4d5d3fb99a10a626956bccc7215f6b68b16
 F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f
 F src/btree.c f5c1b3d88ad62ab4682de37229168a00b87fc948
 F src/btree.h 066444ee25bd6e6accb997bfd2cf5ace14dbcd00
-F src/build.c 6bd68dc730b01c1727738f8e4b5c730eb0ddb421
+F src/build.c f6b2616b60b19520b93cd26f21f76a8d2fbadc49
 F src/callback.c 31d22b4919c7645cbcbb1591ce2453e8c677c558
 F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675
 F src/date.c 393c73fc027597e008dcd81454544659e978b05c
@@ -182,7 +182,7 @@ F test/collate6.test 6c9470d1606ee3e564675b229653e320c49ec638
 F test/colmeta.test 6505c73ab58796afcb7c89ba9f429d573fbc6e53
 F test/conflict.test 8a59399f61a14296a9bfed02e0570590a8a79cba
 F test/corrupt.test 18c7a995b1af76a8c8600b996257f2c7b7bff083
-F test/corrupt2.test bf57d744ab00c5822996dc75eedb742ceadb2b0d
+F test/corrupt2.test 572f8df0303d0ce63ddad5c5c9101a83a345ae46
 F test/crash.test 5f5f155393c5685b3842fef79b6fbafa55197d75
 F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
 F test/date.test 63cc718e1d209b10c6b7be8ce72b11addb9f1e04
@@ -436,7 +436,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 92f158643cc3f9fa913ed80e4eef325c33e4bf06
-R 1bcc6f326261ba45e04467f3466527d7
-U drh
-Z 77e39bddd91d33e7ddb2cdeef6f6f6cf
+P e20e76f6d8578f4faab0b101b6d4deb2a8987454
+R 9273c66be575d7182b4b1faa7a816ce7
+U danielk1977
+Z 7529e5f446ae1176d63e7d8f55ccdbb4
index b2c6782e9ec5651f1cf798444590ea06488545a9..41e8959dbe99a91ea63e93dbab45c8b9f56b447f 100644 (file)
@@ -1 +1 @@
-e20e76f6d8578f4faab0b101b6d4deb2a8987454
\ No newline at end of file
+48b2a40008a09881ed9da3548095495a3d4a6647
\ No newline at end of file
index 0316f9c0008a7717b31860f8f52b0db1030c5f73..88e83d2d9f2e32617e5b627364d2db66b8176a6b 100644 (file)
@@ -22,7 +22,7 @@
 **     COMMIT
 **     ROLLBACK
 **
-** $Id: build.c,v 1.413 2007/02/02 12:44:37 drh Exp $
+** $Id: build.c,v 1.414 2007/03/13 16:32:25 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -2357,17 +2357,17 @@ void sqlite3CreateIndex(
     }
     if( !db->init.busy ){
       if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index;
+      if( sqlite3FindTable(db, zName, 0)!=0 ){
+        sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
+        goto exit_create_index;
+      }
+    }
       if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
         if( !ifNotExist ){
           sqlite3ErrorMsg(pParse, "index %s already exists", zName);
         }
         goto exit_create_index;
       }
-      if( sqlite3FindTable(db, zName, 0)!=0 ){
-        sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
-        goto exit_create_index;
-      }
-    }
   }else{
     char zBuf[30];
     int n;
index 616b2bd21a5e19738407c0163efcd9224bf70ab5..cba53f6d25d992f535313bbf4a5e7e380387bd16 100644 (file)
@@ -13,7 +13,7 @@
 # This file implements tests to make sure SQLite does not crash or
 # segfault if it sees a corrupt database file.
 #
-# $Id: corrupt2.test,v 1.3 2007/02/14 12:32:13 drh Exp $
+# $Id: corrupt2.test,v 1.4 2007/03/13 16:32:25 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -105,4 +105,31 @@ do_test corrupt2-1.5 {
 } {1 {database disk image is malformed}}
 db2 close
 
+# Corrupt a database by having 2 indices of the same name:
+do_test corrupt2-2.1 {
+
+  file delete -force corrupt.db
+  file delete -force corrupt.db-journal
+  copy_file test.db corrupt.db
+
+  sqlite3 db2 corrupt.db 
+  execsql {
+    CREATE INDEX a1 ON abc(a);
+    CREATE INDEX a2 ON abc(b);
+    PRAGMA writable_schema = 1;
+    UPDATE sqlite_master 
+      SET name = 'a3', sql = 'CREATE INDEX a3' || substr(sql, 16, 10000)
+      WHERE type = 'index';
+    PRAGMA writable_schema = 0;
+  } db2
+
+  db2 close
+  sqlite3 db2 corrupt.db 
+  catchsql {
+    SELECT * FROM sqlite_master;
+  } db2
+} {1 {malformed database schema - index a3 already exists}}
+
+db2 close
+
 finish_test