summaryrefslogtreecommitdiff
path: root/Android.patch
blob: cd39abcdf1e31733546b16d0c56b595f7a53f23e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
--- orig/shell.c	2023-06-13 13:30:22.470500137 -0700
+++ shell.c	2023-06-13 13:30:22.546500365 -0700
@@ -127,6 +127,11 @@
 #endif
 #include <ctype.h>
 #include <stdarg.h>
+// Begin Android Add
+#ifndef NO_ANDROID_FUNCS
+#include <sqlite3_android.h>
+#endif
+// End Android Add
 
 #if !defined(_WIN32) && !defined(WIN32)
 # include <signal.h>
@@ -246,7 +251,9 @@
 #if SQLITE_OS_WINRT
 #include <intrin.h>
 #endif
+#ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
+#endif
 #include <windows.h>
 
 /* string conversion routines only needed on Win32 */
@@ -20793,6 +20800,21 @@
                             editFunc, 0, 0);
 #endif
 
+// Begin Android Add
+#ifndef NO_ANDROID_FUNCS
+    int err = register_localized_collators(p->db, "en_US", 0);
+    if (err != SQLITE_OK) {
+      fprintf(stderr, "register_localized_collators() failed\n");
+      exit(1);
+    }
+    err = register_android_functions(p->db, 0);
+    if (err != SQLITE_OK) {
+      fprintf(stderr, "register_android_functions() failed\n");
+      exit(1);
+    }
+#endif
+// End Android Add
+
     if( p->openMode==SHELL_OPEN_ZIPFILE ){
       char *zSql = sqlite3_mprintf(
          "CREATE VIRTUAL TABLE zip USING zipfile(%Q);", zDbFilename);
--- orig/sqlite3.c	2023-06-13 13:30:22.494500209 -0700
+++ sqlite3.c	2023-06-13 13:30:22.590500496 -0700
@@ -37314,6 +37314,10 @@
 # include <sys/mount.h>
 #endif
 
+#if defined(__BIONIC__)
+# include <android/fdsan.h>
+#endif
+
 #ifdef HAVE_UTIME
 # include <utime.h>
 #endif
@@ -37922,6 +37926,12 @@
 #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
     osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
 #endif
+
+#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
+    uint64_t tag = android_fdsan_create_owner_tag(
+        ANDROID_FDSAN_OWNER_TYPE_SQLITE, fd);
+    android_fdsan_exchange_owner_tag(fd, 0, tag);
+#endif
   }
   return fd;
 }
@@ -38502,7 +38512,13 @@
 ** and move on.
 */
 static void robust_close(unixFile *pFile, int h, int lineno){
+#if defined(__BIONIC__) && __ANDROID_API__ >= __ANDROID_API_Q__
+  uint64_t tag = android_fdsan_create_owner_tag(
+      ANDROID_FDSAN_OWNER_TYPE_SQLITE, h);
+  if( android_fdsan_close_with_tag(h, tag) ){
+#else
   if( osClose(h) ){
+#endif
     unixLogErrorAtLine(SQLITE_IOERR_CLOSE, "close",
                        pFile ? pFile->zPath : 0, lineno);
   }
@@ -41051,7 +41067,7 @@
   SimulateIOError( rc=1 );
   if( rc!=0 ){
     storeLastErrno((unixFile*)id, errno);
-    return SQLITE_IOERR_FSTAT;
+    return unixLogError(SQLITE_IOERR_FSTAT, "fstat", ((unixFile*)id)->zPath);
   }
   *pSize = buf.st_size;
 
@@ -41087,7 +41103,7 @@
     struct stat buf;              /* Used to hold return values of fstat() */
 
     if( osFstat(pFile->h, &buf) ){
-      return SQLITE_IOERR_FSTAT;
+      return unixLogError(SQLITE_IOERR_FSTAT, "fstat", pFile->zPath);
     }
 
     nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
@@ -41829,7 +41845,7 @@
     ** with the same permissions.
     */
     if( osFstat(pDbFd->h, &sStat) ){
-      rc = SQLITE_IOERR_FSTAT;
+      rc = unixLogError(SQLITE_IOERR_FSTAT, "fstat", pDbFd->zPath);
       goto shm_open_err;
     }
 
@@ -138266,7 +138282,7 @@
   }
   if( pDb->pSchema->file_format>SQLITE_MAX_FILE_FORMAT ){
     sqlite3SetString(pzErrMsg, db, "unsupported file format");
-    rc = SQLITE_ERROR;
+    rc = SQLITE_CORRUPT_BKPT; // Android Change from "rc = SQLITE_ERROR;";
     goto initone_error_out;
   }
 
@@ -185208,7 +185224,9 @@
   ** module with sqlite.
   */
   if( SQLITE_OK==rc
+#ifndef ANDROID    /* fts3_tokenizer disabled for security reasons */
    && SQLITE_OK==(rc=sqlite3Fts3InitHashTable(db,&pHash->hash,"fts3_tokenizer"))
+#endif
    && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
    && SQLITE_OK==(rc = sqlite3_overload_function(db, "offsets", 1))
    && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 1))
@@ -185219,6 +185237,20 @@
     rc = sqlite3_create_module_v2(
         db, "fts3", &fts3Module, (void *)pHash, hashDestroy
     );
+#ifdef SQLITE_ENABLE_FTS3_BACKWARDS
+    if( rc==SQLITE_OK ){
+      pHash->nRef++;
+      rc = sqlite3_create_module_v2(
+          db, "fts1", &fts3Module, (void *)pHash, hashDestroy
+      );
+    }
+    if( rc==SQLITE_OK ){
+      pHash->nRef++;
+      rc = sqlite3_create_module_v2(
+          db, "fts2", &fts3Module, (void *)pHash, hashDestroy
+      );
+    }
+#endif
     if( rc==SQLITE_OK ){
       pHash->nRef++;
       rc = sqlite3_create_module_v2(