/ Check-in [36877448]
Login

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

Overview
Comment:Fix segfaults that might occur after a malloc failure. (CVS 2119)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 368774487e7a0266465f5a1c2701c9b14573d26c
User & Date: drh 2004-11-20 18:13:10
Context
2004-11-20
19:18
Rig the sqliteMalloc() routine so that we can make it fail multiple times in a row. Modify the malloc.test procedure to make malloc fail in this way and verify that the failures are still handled correctly. (CVS 2121) check-in: 519bc9d9 user: drh tags: trunk
18:13
Fix segfaults that might occur after a malloc failure. (CVS 2119) check-in: 36877448 user: drh tags: trunk
08:17
Documentation for REINDEX and ALTER TABLE commands. (CVS 2118) check-in: aceaa5f6 user: danielk1977 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.284 2004/11/19 08:41:34 danielk1977 Exp $
           25  +** $Id: build.c,v 1.285 2004/11/20 18:13:10 drh 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.  Check to see if the schema for the database needs
................................................................................
   132    132     char saveBuf[SAVE_SZ];
   133    133   
   134    134     if( pParse->nErr ) return;
   135    135     assert( pParse->nested<10 );  /* Nesting should only be of limited depth */
   136    136     va_start(ap, zFormat);
   137    137     zSql = sqlite3VMPrintf(zFormat, ap);
   138    138     va_end(ap);
          139  +  if( zSql==0 ){
          140  +    return;   /* A malloc must have failed */
          141  +  }
   139    142     pParse->nested++;
   140    143     memcpy(saveBuf, &pParse->nVar, SAVE_SZ);
   141    144     memset(&pParse->nVar, 0, SAVE_SZ);
   142    145     rc = sqlite3RunParser(pParse, zSql, 0);
   143    146     sqliteFree(zSql);
   144    147     memcpy(&pParse->nVar, saveBuf, SAVE_SZ);
   145    148     pParse->nested--;
................................................................................
   512    515   /*
   513    516   ** The token *pName contains the name of a database (either "main" or
   514    517   ** "temp" or the name of an attached db). This routine returns the
   515    518   ** index of the named database in db->aDb[], or -1 if the named db 
   516    519   ** does not exist.
   517    520   */
   518    521   int findDb(sqlite3 *db, Token *pName){
   519         -  int i;
   520         -  Db *pDb;
   521         -  char *zName = sqlite3NameFromToken(pName);
   522         -  int n = strlen(zName);
   523         -  for(pDb=db->aDb, i=0; i<db->nDb; i++, pDb++){
   524         -    if( n==strlen(pDb->zName) && 0==sqlite3StrICmp(pDb->zName, zName) ){
   525         -      sqliteFree(zName);
   526         -      return i;
          522  +  int i;         /* Database number */
          523  +  int n;         /* Number of characters in the name */
          524  +  Db *pDb;       /* A database whose name space is being searched */
          525  +  char *zName;   /* Name we are searching for */
          526  +
          527  +  zName = sqlite3NameFromToken(pName);
          528  +  if( zName ){
          529  +    n = strlen(zName);
          530  +    for(pDb=db->aDb, i=0; i<db->nDb; i++, pDb++){
          531  +      if( n==strlen(pDb->zName) && 0==sqlite3StrICmp(pDb->zName, zName) ){
          532  +        sqliteFree(zName);
          533  +        return i;
          534  +      }
   527    535       }
          536  +    sqliteFree(zName);
   528    537     }
   529         -  sqliteFree(zName);
   530    538     return -1;
   531    539   }
   532    540   
   533    541   /* The table or view or trigger name is passed to this routine via tokens
   534    542   ** pName1 and pName2. If the table name was fully qualified, for example:
   535    543   **
   536    544   ** CREATE TABLE xxx.yyy (...);

Changes to src/expr.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.170 2004/11/12 03:56:15 drh Exp $
           15  +** $Id: expr.c,v 1.171 2004/11/20 18:13:10 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** Return the 'affinity' of the expression pExpr if any.
    22     22   **
................................................................................
   216    216     int depth;
   217    217     if( v==0 ) return 0;
   218    218     if( pParse->nested==0 ){
   219    219       sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", pToken);
   220    220       return 0;
   221    221     }
   222    222     p = sqlite3Expr(TK_REGISTER, 0, 0, pToken);
          223  +  if( p==0 ){
          224  +    return 0;  /* Malloc failed */
          225  +  }
   223    226     depth = atoi(&pToken->z[1]);
   224    227     if( depth>=0 ){
   225    228       p->iTable = pParse->nMem++;
   226    229       sqlite3VdbeAddOp(v, OP_Dup, depth, 0);
   227    230       sqlite3VdbeAddOp(v, OP_MemStore, p->iTable, 1);
   228    231     }else{
   229    232       p->iTable = -1-depth;