1--- orig/shell.c 2021-07-12 20:54:40.989319871 +0100 2+++ shell.c 2021-07-12 20:54:51.609392247 +0100 3@@ -95,6 +95,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@@ -12957,6 +12962,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);", p->zDbFilename); 38--- orig/sqlite3.c 2021-07-12 20:54:40.969319735 +0100 39+++ sqlite3.c 2021-07-12 20:54:51.609392247 +0100 40@@ -33407,6 +33407,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@@ -34167,6 +34171,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@@ -34747,7 +34757,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@@ -37281,7 +37297,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@@ -37317,7 +37333,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@@ -38012,7 +38028,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@@ -128302,7 +128318,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@@ -170259,13 +170275,25 @@ 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, "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 && SQLITE_OK==(rc = sqlite3_overload_function(db, "matchinfo", 2)) 125 && SQLITE_OK==(rc = sqlite3_overload_function(db, "optimize", 1)) 126 ){ 127+#ifdef SQLITE_ENABLE_FTS3_BACKWARDS 128+ rc = sqlite3_create_module_v2( 129+ db, "fts1", &fts3Module, (void *)pHash, 0 130+ ); 131+ if(rc) return rc; 132+ rc = sqlite3_create_module_v2( 133+ db, "fts2", &fts3Module, (void *)pHash, 0 134+ ); 135+ if(rc) return rc; 136+#endif 137 rc = sqlite3_create_module_v2( 138 db, "fts3", &fts3Module, (void *)pHash, hashDestroy 139 ); 140