/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/build.c.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
...
132
133
134
135
136
137
138



139
140
141
142
143
144
145
...
512
513
514
515
516
517
518
519
520



521

522
523
524
525
526
527
528
529

530
531
532
533
534
535
536
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.284 2004/11/19 08:41:34 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Check to see if the schema for the database needs
................................................................................
  char saveBuf[SAVE_SZ];

  if( pParse->nErr ) return;
  assert( pParse->nested<10 );  /* Nesting should only be of limited depth */
  va_start(ap, zFormat);
  zSql = sqlite3VMPrintf(zFormat, ap);
  va_end(ap);



  pParse->nested++;
  memcpy(saveBuf, &pParse->nVar, SAVE_SZ);
  memset(&pParse->nVar, 0, SAVE_SZ);
  rc = sqlite3RunParser(pParse, zSql, 0);
  sqliteFree(zSql);
  memcpy(&pParse->nVar, saveBuf, SAVE_SZ);
  pParse->nested--;
................................................................................
/*
** The token *pName contains the name of a database (either "main" or
** "temp" or the name of an attached db). This routine returns the
** index of the named database in db->aDb[], or -1 if the named db 
** does not exist.
*/
int findDb(sqlite3 *db, Token *pName){
  int i;
  Db *pDb;



  char *zName = sqlite3NameFromToken(pName);

  int n = strlen(zName);
  for(pDb=db->aDb, i=0; i<db->nDb; i++, pDb++){
    if( n==strlen(pDb->zName) && 0==sqlite3StrICmp(pDb->zName, zName) ){
      sqliteFree(zName);
      return i;
    }
  }
  sqliteFree(zName);

  return -1;
}

/* The table or view or trigger name is passed to this routine via tokens
** pName1 and pName2. If the table name was fully qualified, for example:
**
** CREATE TABLE xxx.yyy (...);







|







 







>
>
>







 







|
|
>
>
>
|
>
|
|
|
|
|
|
|
|
>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
...
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
**     CREATE INDEX
**     DROP INDEX
**     creating ID lists
**     BEGIN TRANSACTION
**     COMMIT
**     ROLLBACK
**
** $Id: build.c,v 1.285 2004/11/20 18:13:10 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** This routine is called when a new SQL statement is beginning to
** be parsed.  Check to see if the schema for the database needs
................................................................................
  char saveBuf[SAVE_SZ];

  if( pParse->nErr ) return;
  assert( pParse->nested<10 );  /* Nesting should only be of limited depth */
  va_start(ap, zFormat);
  zSql = sqlite3VMPrintf(zFormat, ap);
  va_end(ap);
  if( zSql==0 ){
    return;   /* A malloc must have failed */
  }
  pParse->nested++;
  memcpy(saveBuf, &pParse->nVar, SAVE_SZ);
  memset(&pParse->nVar, 0, SAVE_SZ);
  rc = sqlite3RunParser(pParse, zSql, 0);
  sqliteFree(zSql);
  memcpy(&pParse->nVar, saveBuf, SAVE_SZ);
  pParse->nested--;
................................................................................
/*
** The token *pName contains the name of a database (either "main" or
** "temp" or the name of an attached db). This routine returns the
** index of the named database in db->aDb[], or -1 if the named db 
** does not exist.
*/
int findDb(sqlite3 *db, Token *pName){
  int i;         /* Database number */
  int n;         /* Number of characters in the name */
  Db *pDb;       /* A database whose name space is being searched */
  char *zName;   /* Name we are searching for */

  zName = sqlite3NameFromToken(pName);
  if( zName ){
    n = strlen(zName);
    for(pDb=db->aDb, i=0; i<db->nDb; i++, pDb++){
      if( n==strlen(pDb->zName) && 0==sqlite3StrICmp(pDb->zName, zName) ){
        sqliteFree(zName);
        return i;
      }
    }
    sqliteFree(zName);
  }
  return -1;
}

/* The table or view or trigger name is passed to this routine via tokens
** pName1 and pName2. If the table name was fully qualified, for example:
**
** CREATE TABLE xxx.yyy (...);

Changes to src/expr.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
216
217
218
219
220
221
222



223
224
225
226
227
228
229
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.170 2004/11/12 03:56:15 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
................................................................................
  int depth;
  if( v==0 ) return 0;
  if( pParse->nested==0 ){
    sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", pToken);
    return 0;
  }
  p = sqlite3Expr(TK_REGISTER, 0, 0, pToken);



  depth = atoi(&pToken->z[1]);
  if( depth>=0 ){
    p->iTable = pParse->nMem++;
    sqlite3VdbeAddOp(v, OP_Dup, depth, 0);
    sqlite3VdbeAddOp(v, OP_MemStore, p->iTable, 1);
  }else{
    p->iTable = -1-depth;







|







 







>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.171 2004/11/20 18:13:10 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
................................................................................
  int depth;
  if( v==0 ) return 0;
  if( pParse->nested==0 ){
    sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", pToken);
    return 0;
  }
  p = sqlite3Expr(TK_REGISTER, 0, 0, pToken);
  if( p==0 ){
    return 0;  /* Malloc failed */
  }
  depth = atoi(&pToken->z[1]);
  if( depth>=0 ){
    p->iTable = pParse->nMem++;
    sqlite3VdbeAddOp(v, OP_Dup, depth, 0);
    sqlite3VdbeAddOp(v, OP_MemStore, p->iTable, 1);
  }else{
    p->iTable = -1-depth;