Bug 1449169, NSS should assume SQlite >= 3.5.0 and support read-only database opening using the sqlite3_open_v2 API, r=dueno
authorKai Engert <kaie@kuix.de>
Mon, 16 Apr 2018 16:19:32 +0200
changeset 14330 e7ccf89f73a2ef86a154a790fd67421f98969bc9
parent 14329 c1a4035420c31049c1e7b4f77043a09eb6ab57f0
child 14331 3e452651e2829315f0961a08a0dad808171926c7
push id3065
push userkaie@kuix.de
push dateMon, 16 Apr 2018 14:18:54 +0000
reviewersdueno
bugs1449169
Bug 1449169, NSS should assume SQlite >= 3.5.0 and support read-only database opening using the sqlite3_open_v2 API, r=dueno
lib/softoken/sdb.c
--- a/lib/softoken/sdb.c
+++ b/lib/softoken/sdb.c
@@ -639,23 +639,28 @@ sdb_closeDBLocal(SDBPrivate *sdb_p, sqli
 
 /*
  * wrapper to sqlite3_open which also sets the busy_timeout
  */
 static int
 sdb_openDB(const char *name, sqlite3 **sqlDB, int flags)
 {
     int sqlerr;
-    /*
-     * in sqlite3 3.5.0, there is a new open call that allows us
-     * to specify read only. Most new OS's are still on 3.3.x (including
-     * NSS's internal version and the version shipped with Firefox).
-     */
+    int openFlags;
+
     *sqlDB = NULL;
-    sqlerr = sqlite3_open(name, sqlDB);
+
+    if (flags & SDB_RDONLY) {
+        openFlags = SQLITE_OPEN_READONLY;
+    } else {
+        openFlags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
+    }
+
+    /* Requires SQLite 3.5.0 or newer. */
+    sqlerr = sqlite3_open_v2(name, sqlDB, openFlags, NULL);
     if (sqlerr != SQLITE_OK) {
         return sqlerr;
     }
 
     sqlerr = sqlite3_busy_timeout(*sqlDB, SDB_SQLITE_BUSY_TIMEOUT);
     if (sqlerr != SQLITE_OK) {
         sqlite3_close(*sqlDB);
         *sqlDB = NULL;