SQLite
Check-in [011e7db253]
Not logged in

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

Overview
SHA1 Hash:011e7db253f9a60c19977215eab1687930f15637
Date: 2007-05-07 19:31:16
User: drh
Comment:Fix an NULL deref in the randomblob() function following a malloc failure. (CVS 3940)
Tags And Properties
Changes
hide diffs unified diffs patch

Changes to src/func.c

12 ** This file contains the C functions that implement various SQL 12 ** This file contains the C functions that implement various SQL 13 ** functions of SQLite. 13 ** functions of SQLite. 14 ** 14 ** 15 ** There is only one exported symbol in this file - the function 15 ** There is only one exported symbol in this file - the function 16 ** sqliteRegisterBuildinFunctions() found at the bottom of the file. 16 ** sqliteRegisterBuildinFunctions() found at the bottom of the file. 17 ** All other code has file scope. 17 ** All other code has file scope. 18 ** 18 ** 19 ** $Id: func.c,v 1.145 2007/05/04 13:15:56 drh Exp $ | 19 ** $Id: func.c,v 1.146 2007/05/07 19:31:16 drh Exp $ 20 */ 20 */ 21 #include "sqliteInt.h" 21 #include "sqliteInt.h" 22 #include <ctype.h> 22 #include <ctype.h> 23 /* #include <math.h> */ 23 /* #include <math.h> */ 24 #include <stdlib.h> 24 #include <stdlib.h> 25 #include <assert.h> 25 #include <assert.h> 26 #include "vdbeInt.h" 26 #include "vdbeInt.h" ................................................................................................................................................................................ 293 sqlite3_value **argv 293 sqlite3_value **argv 294 ){ 294 ){ 295 int n; 295 int n; 296 unsigned char *p; 296 unsigned char *p; 297 assert( argc==1 ); 297 assert( argc==1 ); 298 n = sqlite3_value_int(argv[0]); 298 n = sqlite3_value_int(argv[0]); 299 if( n<1 ) n = 1; 299 if( n<1 ) n = 1; 300 p = sqlite3_malloc(n); | 300 p = sqliteMalloc(n); > 301 if( p ){ 301 sqlite3Randomness(n, p); | 302 sqlite3Randomness(n, p); 302 sqlite3_result_blob(context, (char*)p, n, sqlite3_free); | 303 sqlite3_result_blob(context, (char*)p, n, sqlite3FreeX); > 304 } 303 } 305 } 304 306 305 /* 307 /* 306 ** Implementation of the last_insert_rowid() SQL function. The return 308 ** Implementation of the last_insert_rowid() SQL function. The return 307 ** value is the same as the sqlite3_last_insert_rowid() API function. 309 ** value is the same as the sqlite3_last_insert_rowid() API function. 308 */ 310 */ 309 static void last_insert_rowid( 311 static void last_insert_rowid(

Changes to test/malloc8.test

7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others. 8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give. 9 # 9 # 10 #*********************************************************************** 10 #*********************************************************************** 11 # This file contains additional out-of-memory checks (see malloc.tcl) 11 # This file contains additional out-of-memory checks (see malloc.tcl) 12 # added to expose a bug in out-of-memory handling for sqlite3_value_text() 12 # added to expose a bug in out-of-memory handling for sqlite3_value_text() 13 # 13 # 14 # $Id: malloc8.test,v 1.2 2007/04/30 21:39:16 drh Exp $ | 14 # $Id: malloc8.test,v 1.3 2007/05/07 19:31:17 drh Exp $ 15 15 16 set testdir [file dirname $argv0] 16 set testdir [file dirname $argv0] 17 source $testdir/tester.tcl 17 source $testdir/tester.tcl 18 18 19 # Only run these tests if memory debugging is turned on. 19 # Only run these tests if memory debugging is turned on. 20 # 20 # 21 if {[info command sqlite_malloc_stat]==""} { 21 if {[info command sqlite_malloc_stat]==""} { ................................................................................................................................................................................ 143 } 143 } 144 do_malloc_test 4 -sqlbody { 144 do_malloc_test 4 -sqlbody { 145 SELECT julianday(a,a) FROM t1; 145 SELECT julianday(a,a) FROM t1; 146 } 146 } 147 do_malloc_test 5 -sqlbody { 147 do_malloc_test 5 -sqlbody { 148 SELECT 1 FROM t1 WHERE a LIKE 'hello' ESCAPE NULL; 148 SELECT 1 FROM t1 WHERE a LIKE 'hello' ESCAPE NULL; 149 } 149 } > 150 do_malloc_test 6 -sqlbody { > 151 SELECT hex(randomblob(100)); > 152 } 150 153 151 # Ensure that no file descriptors were leaked. 154 # Ensure that no file descriptors were leaked. 152 do_test malloc-99.X { 155 do_test malloc-99.X { 153 catch {db close} 156 catch {db close} 154 set sqlite_open_file_count 157 set sqlite_open_file_count 155 } {0} 158 } {0} 156 159 157 sqlite_malloc_fail 0 160 sqlite_malloc_fail 0 158 finish_test 161 finish_test