/ Check-in [eb91612f]
Login

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

Overview
Comment:Fix a NULL pointer deference following malloc failure. Bug discovered by klocwork. (CVS 3328)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:eb91612f4646b15c2b8398c5225669419b03b531
User & Date: drh 2006-07-11 12:40:25
Context
2006-07-11
13:15
Prevent memory leak and possible NULL pointer deference after malloc failure. Ticket #1886. (CVS 3329) check-in: b1f326e6 user: drh tags: trunk
12:40
Fix a NULL pointer deference following malloc failure. Bug discovered by klocwork. (CVS 3328) check-in: eb91612f user: drh tags: trunk
10:42
Fix a possible NULL-pointer deference following a malloc failure. Error discovered by Klocwork. (CVS 3327) check-in: 368bcf26 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/util.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
....
1353
1354
1355
1356
1357
1358
1359

1360
1361

1362
1363
1364
1365
1366
1367
1368
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.190 2006/06/27 13:20:21 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <stdarg.h>
#include <ctype.h>

/*
................................................................................
void *sqlite3HexToBlob(const char *z){
  char *zBlob;
  int i;
  int n = strlen(z);
  if( n%2 ) return 0;

  zBlob = (char *)sqliteMalloc(n/2);

  for(i=0; i<n; i+=2){
    zBlob[i/2] = (hexToInt(z[i])<<4) | hexToInt(z[i+1]);

  }
  return zBlob;
}
#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */

#if defined(SQLITE_TEST)
/*







|







 







>
|
|
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
....
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.191 2006/07/11 12:40:25 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
#include <stdarg.h>
#include <ctype.h>

/*
................................................................................
void *sqlite3HexToBlob(const char *z){
  char *zBlob;
  int i;
  int n = strlen(z);
  if( n%2 ) return 0;

  zBlob = (char *)sqliteMalloc(n/2);
  if( zBlob ){
    for(i=0; i<n; i+=2){
      zBlob[i/2] = (hexToInt(z[i])<<4) | hexToInt(z[i+1]);
    }
  }
  return zBlob;
}
#endif /* !SQLITE_OMIT_BLOB_LITERAL || SQLITE_HAS_CODEC */

#if defined(SQLITE_TEST)
/*

Changes to test/malloc.test.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#***********************************************************************
# This file attempts to check the library in an out-of-memory situation.
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
# command (sqlite_malloc_fail N) which causes the N-th malloc to fail.  This
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.33 2006/06/26 12:50:09 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {
................................................................................
} -sqlbody {
  DROP TABLE IF EXISTS t1;
  CREATE TABLE t1(
     a int, b float, c double, d text, e varchar(20),
     primary key(a,b,c)
  );
  CREATE INDEX i1 ON t1(a,b);
  INSERT INTO t1 VALUES(1,2.3,4.5,'hi','there');
  INSERT INTO t1 VALUES(6,7.0,0.8,'hello','out yonder');
  SELECT * FROM t1;
  SELECT avg(b) FROM t1 GROUP BY a HAVING b>20.0;
  DELETE FROM t1 WHERE a IN (SELECT min(a) FROM t1);
  SELECT count(*) FROM t1;
} 








|







 







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#***********************************************************************
# This file attempts to check the library in an out-of-memory situation.
# When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
# command (sqlite_malloc_fail N) which causes the N-th malloc to fail.  This
# special feature is used to see what happens in the library if a malloc
# were to really fail due to an out-of-memory situation.
#
# $Id: malloc.test,v 1.34 2006/07/11 12:40:25 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Only run these tests if memory debugging is turned on.
#
if {[info command sqlite_malloc_stat]==""} {
................................................................................
} -sqlbody {
  DROP TABLE IF EXISTS t1;
  CREATE TABLE t1(
     a int, b float, c double, d text, e varchar(20),
     primary key(a,b,c)
  );
  CREATE INDEX i1 ON t1(a,b);
  INSERT INTO t1 VALUES(1,2.3,4.5,'hi',x'746865726500');
  INSERT INTO t1 VALUES(6,7.0,0.8,'hello','out yonder');
  SELECT * FROM t1;
  SELECT avg(b) FROM t1 GROUP BY a HAVING b>20.0;
  DELETE FROM t1 WHERE a IN (SELECT min(a) FROM t1);
  SELECT count(*) FROM t1;
}