/ Check-in [48b2a400]
Login

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

Overview
Comment:Do not crash when a corrupt database contains two indices with the same name. (CVS 3684)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 48b2a40008a09881ed9da3548095495a3d4a6647
User & Date: danielk1977 2007-03-13 16:32:25
Context
2007-03-13
16:33
Add hyperlink anchors to the lockingv3.html document. (CVS 3685) check-in: 3e66ea6f user: drh tags: trunk
16:32
Do not crash when a corrupt database contains two indices with the same name. (CVS 3684) check-in: 48b2a400 user: danielk1977 tags: trunk
2007-03-12
23:48
Clarify the use of loop variables in a expr.c. (CVS 3683) check-in: e20e76f6 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.413 2007/02/02 12:44:37 drh Exp $
           25  +** $Id: build.c,v 1.414 2007/03/13 16:32:25 danielk1977 Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   #include <ctype.h>
    29     29   
    30     30   /*
    31     31   ** This routine is called when a new SQL statement is beginning to
    32     32   ** be parsed.  Initialize the pParse structure as needed.
................................................................................
  2353   2353       if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index;
  2354   2354       if( zName==0 ) goto exit_create_index;
  2355   2355       if( SQLITE_OK!=sqlite3CheckObjectName(pParse, zName) ){
  2356   2356         goto exit_create_index;
  2357   2357       }
  2358   2358       if( !db->init.busy ){
  2359   2359         if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto exit_create_index;
         2360  +      if( sqlite3FindTable(db, zName, 0)!=0 ){
         2361  +        sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
         2362  +        goto exit_create_index;
         2363  +      }
         2364  +    }
  2360   2365         if( sqlite3FindIndex(db, zName, pDb->zName)!=0 ){
  2361   2366           if( !ifNotExist ){
  2362   2367             sqlite3ErrorMsg(pParse, "index %s already exists", zName);
  2363   2368           }
  2364   2369           goto exit_create_index;
  2365   2370         }
  2366         -      if( sqlite3FindTable(db, zName, 0)!=0 ){
  2367         -        sqlite3ErrorMsg(pParse, "there is already a table named %s", zName);
  2368         -        goto exit_create_index;
  2369         -      }
  2370         -    }
  2371   2371     }else{
  2372   2372       char zBuf[30];
  2373   2373       int n;
  2374   2374       Index *pLoop;
  2375   2375       for(pLoop=pTab->pIndex, n=1; pLoop; pLoop=pLoop->pNext, n++){}
  2376   2376       sprintf(zBuf,"_%d",n);
  2377   2377       zName = 0;

Changes to test/corrupt2.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests to make sure SQLite does not crash or
    14     14   # segfault if it sees a corrupt database file.
    15     15   #
    16         -# $Id: corrupt2.test,v 1.3 2007/02/14 12:32:13 drh Exp $
           16  +# $Id: corrupt2.test,v 1.4 2007/03/13 16:32:25 danielk1977 Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   # The following tests - corrupt2-1.* - create some databases corrupted in
    22     22   # specific ways and ensure that SQLite detects them as corrupt.
    23     23   #
................................................................................
    99     99     close $f
   100    100   
   101    101     sqlite3 db2 corrupt.db
   102    102     catchsql {
   103    103       SELECT * FROM sqlite_master;
   104    104     } db2
   105    105   } {1 {database disk image is malformed}}
          106  +db2 close
          107  +
          108  +# Corrupt a database by having 2 indices of the same name:
          109  +do_test corrupt2-2.1 {
          110  +
          111  +  file delete -force corrupt.db
          112  +  file delete -force corrupt.db-journal
          113  +  copy_file test.db corrupt.db
          114  +
          115  +  sqlite3 db2 corrupt.db 
          116  +  execsql {
          117  +    CREATE INDEX a1 ON abc(a);
          118  +    CREATE INDEX a2 ON abc(b);
          119  +    PRAGMA writable_schema = 1;
          120  +    UPDATE sqlite_master 
          121  +      SET name = 'a3', sql = 'CREATE INDEX a3' || substr(sql, 16, 10000)
          122  +      WHERE type = 'index';
          123  +    PRAGMA writable_schema = 0;
          124  +  } db2
          125  +
          126  +  db2 close
          127  +  sqlite3 db2 corrupt.db 
          128  +  catchsql {
          129  +    SELECT * FROM sqlite_master;
          130  +  } db2
          131  +} {1 {malformed database schema - index a3 already exists}}
          132  +
   106    133   db2 close
   107    134   
   108    135   finish_test