Hi,

I'm getting a crash in the sqlite shell on Windows 7 in sqlite3 version 3.12.1.


I can reprduce it with the console commands
      echo "SELECT 1;" > tmp.sql
      sqlite3 :memory: -init tmp.sql >log


What seems to happen is that sqlite3_initialise is never called and 
consequently the malloc function pointers (specifically 
sqlite3GlobalConfig.m.xRoundup) are null.


Call stack for the crash:-

00 0044f0e4 00275700 0x0
01 0044f108 00241699 sqlite3!mallocWithAlarm(int n = 0n164, void ** pp = 
0x0044f118)+0x10 
[c:\pf\swgraphics\tools\extern_con\main\sqlite\src-split\sqlite3-1.c @ 22226]
02 0044f11c 002416e1 sqlite3!sqlite3Malloc(unsigned int64 n = 0xa4)+0x49 
[c:\pf\swgraphics\tools\extern_con\main\sqlite\src-split\sqlite3-1.c @ 22268]
03 0044f130 00276839 sqlite3!sqlite3MallocZero(unsigned int64 n = 0xa4)+0x11 
[c:\pf\swgraphics\tools\extern_con\main\sqlite\src-split\sqlite3-1.c @ 22568]
04 0044f150 0027696f sqlite3!winMbcsToUnicode(char * zFilename = 0x006d6b50 
"CREATE TABLE IF NOT EXISTS test_results ")+0x69 
[c:\pf\swgraphics\tools\extern_con\main\sqlite\src-split\sqlite3-2.c @ 9682]
05 0044f164 00221ef3 sqlite3!sqlite3_win32_mbcs_to_utf8(char * zFilename = 
0x006d6b50 "CREATE TABLE IF NOT EXISTS test_results ")+0xf 
[c:\pf\swgraphics\tools\extern_con\main\sqlite\src-split\sqlite3-2.c @ 9732]
06 0044f184 00221f89 sqlite3!local_getline(char * zLine = 0x006d6b50 "CREATE 
TABLE IF NOT EXISTS test_results ", struct _iobuf * in = 0x00325410)+0x123 
[c:\pf\swgraphics\tools\extern_con\main\sqlite\src-split\shell.c @ 490]
07 0044f1a0 0022528c sqlite3!one_input_line(struct _iobuf * in = 0x00325410, 
char * zPrior = 0x00000000 "", int isContinuation = 0n0)+0x19 
[c:\pf\swgraphics\tools\extern_con\main\sqlite\src-split\shell.c @ 526]
08 0044f254 0022c715 sqlite3!process_input(struct ShellState * p = 0x0044f2f4, 
struct _iobuf * in = 0x00325410)+0xbc 
[c:\pf\swgraphics\tools\extern_con\main\sqlite\src-split\shell.c @ 4399]
09 0044f274 0022d167 sqlite3!process_sqliterc(struct ShellState * p = 
0x0044f2f4, char * sqliterc_override = 0x006d7e88 
"C:\pf\swgraphics\rogueddk\MAIN\tools\intern\usc2\perf.db.sql")+0xc5 
[c:\pf\swgraphics\tools\extern_con\main\sqlite\src-split\shell.c @ 4593]
0a 0044f7c8 002e454d sqlite3!main(int argc = 0n6, char ** argv = 
0x006d7e18)+0x7f7 
[c:\pf\swgraphics\tools\extern_con\main\sqlite\src-split\shell.c @ 4875]


The crash only happens if the shell output is redirected to a file otherwise 
the call sequence
  process_sqliterc
->utf8_printf(stderr,"-- Loading resources from %s\n",sqliterc)
->sqlite3_vmprintf
->sqlite3_initialize
causes the malloc functions to be set up.


I fixed it with this patch

--- orig-src/sqlite-src-3120100/src/os_win.c    2016-04-18 13:40:00.295629200 
+0100
+++ sqlite-src-3120100/src/os_win.c     2016-04-18 13:35:52.358129200 +0100
@@ -1693,6 +1693,10 @@
   LPWSTR zMbcsFilename;
   int codepage = osAreFileApisANSI() ? CP_ACP : CP_OEMCP;


+  #ifndef SQLITE_OMIT_AUTOINIT
+  if( sqlite3_initialize() ) return 0;
+  #endif
+
   nByte = osMultiByteToWideChar(codepage, 0, zFilename, -1, NULL,
                                 0)*sizeof(WCHAR);
   if( nByte==0 ){

Reply via email to