• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1--- orig/shell.c	2022-09-01 12:39:01.340032408 +0100
2+++ shell.c	2022-09-01 12:39:01.528030292 +0100
3@@ -107,6 +107,11 @@
4 #endif
5 #include <ctype.h>
6 #include <stdarg.h>
7+// Begin Android Add
8+#ifndef NO_ANDROID_FUNCS
9+#include <sqlite3_android.h>
10+#endif
11+// End Android Add
12
13 #if !defined(_WIN32) && !defined(WIN32)
14 # include <signal.h>
15@@ -16177,6 +16182,22 @@
16     sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0,
17                             editFunc, 0, 0);
18 #endif
19+
20+// Begin Android Add
21+#ifndef NO_ANDROID_FUNCS
22+    int err = register_localized_collators(p->db, "en_US", 0);
23+    if (err != SQLITE_OK) {
24+      fprintf(stderr, "register_localized_collators() failed\n");
25+      exit(1);
26+    }
27+    err = register_android_functions(p->db, 0);
28+    if (err != SQLITE_OK) {
29+      fprintf(stderr, "register_android_functions() failed\n");
30+      exit(1);
31+    }
32+#endif
33+// End Android Add
34+
35     if( p->openMode==SHELL_OPEN_ZIPFILE ){
36       char *zSql = sqlite3_mprintf(
37          "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
38--- orig/sqlite3.c	2022-09-01 12:39:01.356032228 +0100
39+++ sqlite3.c	2022-09-01 12:39:15.955867966 +0100
40@@ -35608,6 +35608,10 @@
41 # include <sys/mount.h>
42 #endif
43
44+#if defined(__BIONIC__)
45+# include <android/fdsan.h>
46+#endif
47+
48 #ifdef HAVE_UTIME
49 # include <utime.h>
50 #endif
51@@ -36170,6 +36174,12 @@
52 #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
53     osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
54 #endif
55+
56+#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
57+    uint64_t tag = android_fdsan_create_owner_tag(
58+        ANDROID_FDSAN_OWNER_TYPE_SQLITE, fd);
59+    android_fdsan_exchange_owner_tag(fd, 0, tag);
60+#endif
61   }
62   return fd;
63 }
64@@ -36750,7 +36760,13 @@
65 ** and move on.
66 */
67 static void robust_close(unixFile *pFile, int h, int lineno){
68+#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
69+  uint64_t tag = android_fdsan_create_owner_tag(
70+      ANDROID_FDSAN_OWNER_TYPE_SQLITE, h);
71+  if( android_fdsan_close_with_tag(h, tag) ){
72+#else
73   if( osClose(h) ){
74+#endif
75     unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
76                        pFile ? pFile->zPath : 0, lineno);
77   }
78@@ -39305,7 +39321,7 @@
79   SimulateIOError( rc=1 );
80   if( rc!=0 ){
81     storeLastErrno((unixFile*)id, errno);
82-    return SQLITE_IOERR_FSTAT;
83+    return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath);
84   }
85   *pSize = buf.st_size;
86
87@@ -39341,7 +39357,7 @@
88     struct stat buf;              /* Used to hold return values of fstat() */
89
90     if( osFstat(pFile->h, &buf) ){
91-      return SQLITE_IOERR_FSTAT;
92+      return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
93     }
94
95     nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
96@@ -40083,7 +40099,7 @@
97     ** with the same permissions.
98     */
99     if( osFstat(pDbFd->h, &sStat) ){
100-      rc = SQLITE_IOERR_FSTAT;
101+      rc = unixLogError(SQLITE_IOERR_FSTAT, "fstat", pDbFd->zPath);
102       goto shm_open_err;
103     }
104
105@@ -134802,7 +134818,7 @@
106   }
107   if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
108     sqlite3SetString(pzErrMsg, db, "unsupported file format");
109-    rc = SQLITE_ERROR;
110+    rc = SQLITE_CORRUPT_BKPT; // Android Change from "rc = SQLITE_ERROR;";
111     goto initone_error_out;
112   }
113
114@@ -180855,7 +180871,9 @@
115   ** module with sqlite.
116   */
117   if( SQLITE_OK==rc
118+#ifndef ANDROID    /* fts3_tokenizer disabled for security reasons */
119    && SQLITE_OK==(rc=sqlite3Fts3InitHashTable(db,&pHash->hash,"fts3_tokenizer"))
120+#endif
121    && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
122    && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
123    && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
124@@ -180866,6 +180884,20 @@
125     rc = sqlite3_create_module_v2(
126         db, "fts3", &fts3Module, (void *)pHash, hashDestroy
127     );
128+#ifdef SQLITE_ENABLE_FTS3_BACKWARDS
129+    if( rc==SQLITE_OK ){
130+      pHash->nRef++;
131+      rc = sqlite3_create_module_v2(
132+          db, "fts1", &fts3Module, (void *)pHash, hashDestroy
133+      );
134+    }
135+    if( rc==SQLITE_OK ){
136+      pHash->nRef++;
137+      rc = sqlite3_create_module_v2(
138+          db, "fts2", &fts3Module, (void *)pHash, hashDestroy
139+      );
140+    }
141+#endif
142     if( rc==SQLITE_OK ){
143       pHash->nRef++;
144       rc = sqlite3_create_module_v2(
145