Skip to content

Commit c10cb2b

Browse files
Jon Larimerandi34
authored andcommitted
sqlite: upgrade to patched SQLite 3.7.11 - DO NOT MERGE
Downloaded from https://www.sqlite.org/2015/sqlite3-3.7.11-patched-20150522.tar.gz $ sha256sum sqlite3-3.7.11-patched-20150522.tar.gz d5ddd42b5af5823547e05a1771747e8464afb3f0318e69c8621a4148fdf36a4b sqlite3-3.7.11-patched-20150522.tar.gz dist/orig contains the stock sqlite3 code, as packaged in the ZIP file above. dist contains a copy of dist/orig, but with the Android.patch file applied. Please see Android.patch for a list of differences between stock and Android. This distribution contains 3.7.11 plus several security fixes: https://www.sqlite.org/src/info/eddc05e7bb31fae7 https://www.sqlite.org/src/info/02e3c88fbf6abdcf https://www.sqlite.org/src/info/c494171f77dc2e5e https://www.sqlite.org/src/info/95625ef3adc3c408 https://www.sqlite.org/src/info/0cdf502885ea7e58 https://www.sqlite.org/src/info/586a94e85bc13700 Bug: 20099586 Change-Id: I4f0ca09a2c84e270ab3e7efdd2754b2afbf347a7
1 parent 65efff0 commit c10cb2b

File tree

8 files changed

+276
-188
lines changed

8 files changed

+276
-188
lines changed

dist/Android.patch

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
diff -r -u -d orig/shell.c ./shell.c
2-
--- orig/shell.c 2012-04-19 19:18:38.000000000 -0700
3-
+++ ./shell.c 2012-04-19 19:26:02.000000000 -0700
2+
--- orig/shell.c 2015-08-26 20:02:12.904405871 -0400
3+
+++ ./shell.c 2015-08-26 20:04:05.975485109 -0400
44
@@ -35,6 +35,11 @@
55
#include "sqlite3.h"
66
#include <ctype.h>
@@ -13,7 +13,7 @@ diff -r -u -d orig/shell.c ./shell.c
1313

1414
#if !defined(_WIN32) && !defined(WIN32) && !defined(__OS2__)
1515
# include <signal.h>
16-
@@ -1463,6 +1468,20 @@
16+
@@ -1466,6 +1471,20 @@
1717
#ifndef SQLITE_OMIT_LOAD_EXTENSION
1818
sqlite3_enable_load_extension(p->db, 1);
1919
#endif
@@ -35,8 +35,8 @@ diff -r -u -d orig/shell.c ./shell.c
3535
}
3636

3737
diff -r -u -d orig/sqlite3.c ./sqlite3.c
38-
--- orig/sqlite3.c 2012-04-19 19:18:38.000000000 -0700
39-
+++ ./sqlite3.c 2012-04-19 19:26:02.000000000 -0700
38+
--- orig/sqlite3.c 2015-08-26 20:02:12.912405806 -0400
39+
+++ ./sqlite3.c 2015-08-26 20:04:05.975485109 -0400
4040
@@ -25387,7 +25387,12 @@
4141
#else
4242
{ "pread64", (sqlite3_syscall_ptr)0, 0 },
@@ -65,7 +65,7 @@ diff -r -u -d orig/sqlite3.c ./sqlite3.c
6565

6666
#if SQLITE_ENABLE_LOCKING_STYLE
6767
{ "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
68-
@@ -93937,7 +93948,7 @@
68+
@@ -93936,7 +93947,7 @@
6969
}
7070
if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
7171
sqlite3SetString(pzErrMsg, db, "unsupported file format");
@@ -74,7 +74,7 @@ diff -r -u -d orig/sqlite3.c ./sqlite3.c
7474
goto initone_error_out;
7575
}
7676

77-
@@ -112387,7 +112398,7 @@
77+
@@ -112404,7 +112415,7 @@
7878
extern "C" {
7979
#endif /* __cplusplus */
8080

@@ -83,7 +83,7 @@ diff -r -u -d orig/sqlite3.c ./sqlite3.c
8383

8484
#if 0
8585
} /* extern "C" */
86-
@@ -114717,9 +114728,24 @@
86+
@@ -114734,9 +114745,24 @@
8787
#endif
8888

8989
#ifdef SQLITE_ENABLE_FTS3
@@ -111,7 +111,7 @@ diff -r -u -d orig/sqlite3.c ./sqlite3.c
111111
#endif
112112

113113
#ifdef SQLITE_ENABLE_ICU
114-
@@ -120143,7 +120169,7 @@
114+
@@ -120169,7 +120195,7 @@
115115
** SQLite. If fts3 is built as a dynamically loadable extension, this
116116
** function is called by the sqlite3_extension_init() entry point.
117117
*/
@@ -120,7 +120,7 @@ diff -r -u -d orig/sqlite3.c ./sqlite3.c
120120
int rc = SQLITE_OK;
121121
Fts3Hash *pHash = 0;
122122
const sqlite3_tokenizer_module *pSimple = 0;
123-
@@ -120204,7 +120230,10 @@
123+
@@ -120230,7 +120256,10 @@
124124
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1))
125125
){
126126
rc = sqlite3_create_module_v2(

dist/orig/shell.c

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ struct callback_data {
434434
** .explain ON */
435435
char outfile[FILENAME_MAX]; /* Filename for *out */
436436
const char *zDbFilename; /* name of the database file */
437+
char *zFreeOnClose; /* Filename to free when closing */
437438
const char *zVfs; /* Name of VFS to use */
438439
sqlite3_stmt *pStmt; /* Current statement if any. */
439440
FILE *pLog; /* Write log output here */
@@ -1416,6 +1417,7 @@ static char zHelp[] =
14161417
" tabs Tab-separated values\n"
14171418
" tcl TCL list elements\n"
14181419
".nullvalue STRING Print STRING in place of NULL values\n"
1420+
".open ?FILENAME? Close existing database and reopen FILENAME\n"
14191421
".output FILENAME Send output to FILENAME\n"
14201422
".output stdout Send output to the screen\n"
14211423
".prompt MAIN CONTINUE Replace the standard prompts\n"
@@ -1447,7 +1449,7 @@ static int process_input(struct callback_data *p, FILE *in);
14471449
** Make sure the database is open. If it is not, then open it. If
14481450
** the database fails to open, print an error message and exit.
14491451
*/
1450-
static void open_db(struct callback_data *p){
1452+
static void open_db(struct callback_data *p, int keepAlive){
14511453
if( p->db==0 ){
14521454
sqlite3_open(p->zDbFilename, &p->db);
14531455
db = p->db;
@@ -1458,6 +1460,7 @@ static void open_db(struct callback_data *p){
14581460
if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){
14591461
fprintf(stderr,"Error: unable to open database \"%s\": %s\n",
14601462
p->zDbFilename, sqlite3_errmsg(db));
1463+
if( keepAlive ) return;
14611464
exit(1);
14621465
}
14631466
#ifndef SQLITE_OMIT_LOAD_EXTENSION
@@ -1578,7 +1581,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
15781581
sqlite3_close(pDest);
15791582
return 1;
15801583
}
1581-
open_db(p);
1584+
open_db(p, 0);
15821585
pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
15831586
if( pBackup==0 ){
15841587
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(pDest));
@@ -1603,7 +1606,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
16031606
if( c=='d' && n>1 && strncmp(azArg[0], "databases", n)==0 && nArg==1 ){
16041607
struct callback_data data;
16051608
char *zErrMsg = 0;
1606-
open_db(p);
1609+
open_db(p, 0);
16071610
memcpy(&data, p, sizeof(data));
16081611
data.showHeader = 1;
16091612
data.mode = MODE_Column;
@@ -1620,7 +1623,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
16201623
}else
16211624

16221625
if( c=='d' && strncmp(azArg[0], "dump", n)==0 && nArg<3 ){
1623-
open_db(p);
1626+
open_db(p, 0);
16241627
/* When playing back a "dump", the content might appear in an order
16251628
** which causes immediate foreign key constraints to be violated.
16261629
** So disable foreign-key constraint enforcement to prevent problems. */
@@ -1738,7 +1741,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
17381741
FILE *in; /* The input file */
17391742
int lineno = 0; /* Line number of input file */
17401743

1741-
open_db(p);
1744+
open_db(p, 0);
17421745
nSep = strlen30(p->separator);
17431746
if( nSep==0 ){
17441747
fprintf(stderr, "Error: non-null separator required for import\n");
@@ -1853,7 +1856,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
18531856
if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg<3 ){
18541857
struct callback_data data;
18551858
char *zErrMsg = 0;
1856-
open_db(p);
1859+
open_db(p, 0);
18571860
memcpy(&data, p, sizeof(data));
18581861
data.showHeader = 0;
18591862
data.mode = MODE_List;
@@ -1919,7 +1922,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
19191922
char *zErrMsg = 0;
19201923
zFile = azArg[1];
19211924
zProc = nArg>=3 ? azArg[2] : 0;
1922-
open_db(p);
1925+
open_db(p, 0);
19231926
rc = sqlite3_load_extension(p->db, zFile, zProc, &zErrMsg);
19241927
if( rc!=SQLITE_OK ){
19251928
fprintf(stderr, "Error: %s\n", zErrMsg);
@@ -1998,6 +2001,26 @@ static int do_meta_command(char *zLine, struct callback_data *p){
19982001
"%.*s", (int)ArraySize(p->nullvalue)-1, azArg[1]);
19992002
}else
20002003

2004+
if( c=='o' && strncmp(azArg[0], "open", n)==0 && n>=2 ){
2005+
sqlite3 *savedDb = p->db;
2006+
const char *zSavedFilename = p->zDbFilename;
2007+
char *zNewFilename = 0;
2008+
p->db = 0;
2009+
if( nArg>=2 ){
2010+
p->zDbFilename = zNewFilename = sqlite3_mprintf("%s", azArg[1]);
2011+
}
2012+
open_db(p, 1);
2013+
if( p->db!=0 ){
2014+
sqlite3_close(savedDb);
2015+
sqlite3_free(p->zFreeOnClose);
2016+
p->zFreeOnClose = zNewFilename;
2017+
}else{
2018+
sqlite3_free(zNewFilename);
2019+
p->db = savedDb;
2020+
p->zDbFilename = zSavedFilename;
2021+
}
2022+
}else
2023+
20012024
if( c=='o' && strncmp(azArg[0], "output", n)==0 && nArg==2 ){
20022025
if( p->out!=stdout ){
20032026
fclose(p->out);
@@ -2061,7 +2084,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
20612084
sqlite3_close(pSrc);
20622085
return 1;
20632086
}
2064-
open_db(p);
2087+
open_db(p, 0);
20652088
pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
20662089
if( pBackup==0 ){
20672090
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
@@ -2091,7 +2114,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
20912114
if( c=='s' && strncmp(azArg[0], "schema", n)==0 && nArg<3 ){
20922115
struct callback_data data;
20932116
char *zErrMsg = 0;
2094-
open_db(p);
2117+
open_db(p, 0);
20952118
memcpy(&data, p, sizeof(data));
20962119
data.showHeader = 0;
20972120
data.mode = MODE_Semi;
@@ -2197,7 +2220,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
21972220
char **azResult;
21982221
int nRow;
21992222
char *zErrMsg;
2200-
open_db(p);
2223+
open_db(p, 0);
22012224
if( nArg==1 ){
22022225
rc = sqlite3_get_table(p->db,
22032226
"SELECT name FROM sqlite_master "
@@ -2273,7 +2296,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
22732296
int testctrl = -1;
22742297
int rc = 0;
22752298
int i, n;
2276-
open_db(p);
2299+
open_db(p, 0);
22772300

22782301
/* convert testctrl text option to value. allow any unique prefix
22792302
** of the option name, or a numerical value. */
@@ -2372,7 +2395,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
23722395
}else
23732396

23742397
if( c=='t' && n>4 && strncmp(azArg[0], "timeout", n)==0 && nArg==2 ){
2375-
open_db(p);
2398+
open_db(p, 0);
23762399
sqlite3_busy_timeout(p->db, atoi(azArg[1]));
23772400
}else
23782401

@@ -2381,7 +2404,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
23812404
){
23822405
enableTimer = booleanValue(azArg[1]);
23832406
}else
2384-
2407+
23852408
if( c=='v' && strncmp(azArg[0], "version", n)==0 ){
23862409
printf("SQLite %s %s\n" /*extra-version-info*/,
23872410
sqlite3_libversion(), sqlite3_sourceid());
@@ -2555,7 +2578,7 @@ static int process_input(struct callback_data *p, FILE *in){
25552578
if( zSql && _contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
25562579
&& sqlite3_complete(zSql) ){
25572580
p->cnt = 0;
2558-
open_db(p);
2581+
open_db(p, 0);
25592582
BEGIN_TIMER;
25602583
rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
25612584
END_TIMER;
@@ -2883,7 +2906,7 @@ int main(int argc, char **argv){
28832906
** to the sqlite command-line tool.
28842907
*/
28852908
if( access(data.zDbFilename, 0)==0 ){
2886-
open_db(&data);
2909+
open_db(&data, 0);
28872910
}
28882911

28892912
/* Process the initialization file if there is one. If no -init option
@@ -2975,7 +2998,7 @@ int main(int argc, char **argv){
29752998
rc = do_meta_command(z, &data);
29762999
if( rc && bail_on_error ) return rc;
29773000
}else{
2978-
open_db(&data);
3001+
open_db(&data, 0);
29793002
rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg);
29803003
if( zErrMsg!=0 ){
29813004
fprintf(stderr,"Error: %s\n", zErrMsg);
@@ -2998,7 +3021,7 @@ int main(int argc, char **argv){
29983021
if( zFirstCmd[0]=='.' ){
29993022
rc = do_meta_command(zFirstCmd, &data);
30003023
}else{
3001-
open_db(&data);
3024+
open_db(&data, 0);
30023025
rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
30033026
if( zErrMsg!=0 ){
30043027
fprintf(stderr,"Error: %s\n", zErrMsg);
@@ -3046,5 +3069,6 @@ int main(int argc, char **argv){
30463069
if( data.db ){
30473070
sqlite3_close(data.db);
30483071
}
3072+
sqlite3_free(data.zFreeOnClose);
30493073
return rc;
30503074
}

0 commit comments

Comments
 (0)