Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package sqlite3 for openSUSE:Factory checked 
in at 2026-11-20 14:43:37
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/sqlite3 (Old)
 and      /work/SRC/openSUSE:Factory/.sqlite3.new.1251 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "sqlite3"

Fri Nov 20 14:43:37 2026 rev:180 rq:1398213 version:3.54.1

Changes:
--------
--- /work/SRC/openSUSE:Factory/sqlite3/sqlite3.changes  2026-11-08 
19:21:03.160564967 +0100
+++ /work/SRC/openSUSE:Factory/.sqlite3.new.1251/sqlite3.changes        
2026-11-20 14:43:59.801464730 +0100
@@ -1,0 +2,23 @@
+Mon Nov 16 16:44:59 UTC 2026 - Reinhard Max <[email protected]>
+
+- CVE-2026-119586, bsc#1289174: Arbitrary command execution via
+  dot-commands smuggled through sqlite_schema.sql into the output
+  of the CLI's ".recover" command. Add four patches from upstream:
+  * sqlite-3.54.1-CVE-2026-119586-recover-strip-trailing-sql.patch:
+    omit extraneous text at the end of sqlite_schema.sql values
+    (check-in d684ccc9ec4e41d8).
+  * sqlite-3.54.1-CVE-2026-119586-recover-safe-mode.patch: add
+    the ".safe" dot-command and emit it near the top of scripts
+    generated by ".recover" as defense in depth; ".recover
+    --unsafe" omits it (check-in f2be7c2a98f2dc65).
+  * sqlite-3.54.1-CVE-2026-119586-safe-mode-hardening.patch: make
+    ".safe" unregister writefile(), zipfile() and the fsdir and
+    zipfile virtual tables on already open databases
+    (check-in d486e997908bbd1b).
+  * sqlite-3.54.1-CVE-2026-119586-dump-recover-hardening.patch:
+    also strip trailing text from views, triggers and indexes in
+    ".recover", and keep text from malformed schemas from
+    escaping the SQL comments written by ".dump"
+    (check-in 8981033053d69c0a).
+
+-------------------------------------------------------------------

New:
----
  sqlite-3.54.1-CVE-2026-119586-dump-recover-hardening.patch
  sqlite-3.54.1-CVE-2026-119586-recover-safe-mode.patch
  sqlite-3.54.1-CVE-2026-119586-recover-strip-trailing-sql.patch
  sqlite-3.54.1-CVE-2026-119586-safe-mode-hardening.patch

----------(New B)----------
  New:    (check-in d486e997908bbd1b).
  * sqlite-3.54.1-CVE-2026-119586-dump-recover-hardening.patch:
    also strip trailing text from views, triggers and indexes in
  New:    (check-in d684ccc9ec4e41d8).
  * sqlite-3.54.1-CVE-2026-119586-recover-safe-mode.patch: add
    the ".safe" dot-command and emit it near the top of scripts
  New:  of the CLI's ".recover" command. Add four patches from upstream:
  * sqlite-3.54.1-CVE-2026-119586-recover-strip-trailing-sql.patch:
    omit extraneous text at the end of sqlite_schema.sql values
  New:    --unsafe" omits it (check-in f2be7c2a98f2dc65).
  * sqlite-3.54.1-CVE-2026-119586-safe-mode-hardening.patch: make
    ".safe" unregister writefile(), zipfile() and the fsdir and
----------(New E)----------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ sqlite3.spec ++++++
--- /var/tmp/diff_new_pack.YID7vb/_old  2026-11-20 14:44:02.497578359 +0100
+++ /var/tmp/diff_new_pack.YID7vb/_new  2026-11-20 14:44:02.503578612 +0100
@@ -46,6 +46,14 @@
 Patch3:         sqlite-3.54.1-fix-fts3corrupt4-test-big-endian.patch
 # PATCH-FIX-UPSTREAM sqlite-3.54.1-fix-shell-import-line-count.patch -- 64 bit 
argument printed with %d, wrong on 32 bit big-endian
 Patch4:         sqlite-3.54.1-fix-shell-import-line-count.patch
+# PATCH-FIX-UPSTREAM 
sqlite-3.54.1-CVE-2026-119586-recover-strip-trailing-sql.patch CVE-2026-119586 
-- .recover must not copy text after the schema SQL statement
+Patch5:         sqlite-3.54.1-CVE-2026-119586-recover-strip-trailing-sql.patch
+# PATCH-FIX-UPSTREAM sqlite-3.54.1-CVE-2026-119586-recover-safe-mode.patch 
CVE-2026-119586 -- add .safe command and emit it in .recover output
+Patch6:         sqlite-3.54.1-CVE-2026-119586-recover-safe-mode.patch
+# PATCH-FIX-UPSTREAM sqlite-3.54.1-CVE-2026-119586-safe-mode-hardening.patch 
CVE-2026-119586 -- .safe unregisters file-writing functions on open databases
+Patch7:         sqlite-3.54.1-CVE-2026-119586-safe-mode-hardening.patch
+# PATCH-FIX-UPSTREAM 
sqlite-3.54.1-CVE-2026-119586-dump-recover-hardening.patch CVE-2026-119586 -- 
sanitize .dump comments, strip trailing text for all schema types in .recover
+Patch8:         sqlite-3.54.1-CVE-2026-119586-dump-recover-hardening.patch
 BuildRequires:  automake
 BuildRequires:  libtool
 BuildRequires:  pkgconfig

++++++ sqlite-3.54.1-CVE-2026-119586-dump-recover-hardening.patch ++++++
From: drh <[email protected]>
Date: Wed, 11 Nov 2026 13:17:51 +0000
Subject: [PATCH] Still more hardening against smuggled shell command attacks.

- ".recover" now also omits extraneous text at the end of the
  sqlite_schema.sql field for views, triggers and non-unique indexes,
  not just for tables.
- ".dump" (CLI and ext/misc/dbdump.c) sanitizes error messages that
  are written as SQL comments: control characters are replaced with
  spaces and "*/" is broken up, so text from a malformed schema can no
  longer escape the comment and inject SQL or dot-commands.

Follow-up hardening for CVE-2026-119586 (bsc#1289174).

Upstream check-in: 8981033053d69c0a
https://sqlite.org/src/info/8981033053d69c0a

Backport notes: the upstream test cases added to test/misc01.sql are
appended to test/recover01.sql instead (added by
sqlite-3.54.1-CVE-2026-119586-recover-strip-trailing-sql.patch).
Changes to the Fossil manifest files were dropped.

diff --git a/ext/misc/dbdump.c b/ext/misc/dbdump.c
index 0b93d2b..3b028ca 100644
--- a/ext/misc/dbdump.c
+++ b/ext/misc/dbdump.c
@@ -276,6 +276,30 @@ col_oom:
   return 0;
 }
 
+/*
+** Return a copy of the text z, obtained from sqlite3_malloc(), that is safe
+** to embed inside of a C-style comment in a script of SQL statements and
+** dot-commands.  Newlines and other control characters are changed to spaces,
+** and any end-of-comment sequence is broken up.  Otherwise, text taken from
+** an untrusted database (for example, a table name in an error message)
+** could terminate the comment and put arbitrary SQL, or a line that begins
+** with "." and so is interpreted as a dot-command, into the output.
+*/
+static char *safeCommentText(const char *z){
+  char *zOut = sqlite3_mprintf("%s", z ? z : "");
+  int i;
+  if( zOut==0 ) return 0;
+  for(i=0; zOut[i]; i++){
+    unsigned char c = (unsigned char)zOut[i];
+    if( c<' ' || c==0x7f ){
+      zOut[i] = ' ';
+    }else if( c=='/' && i>0 && zOut[i-1]=='*' ){
+      zOut[i] = ' ';
+    }
+  }
+  return zOut;
+}
+
 /*
 ** Send mprintf-formatted content to the output callback.
 */
@@ -566,8 +590,9 @@ static void output_sql_from_query(
   rc = sqlite3_prepare_v2(p->db, zSql, -1, &pSelect, 0);
   sqlite3_free(zSql);
   if( rc!=SQLITE_OK || !pSelect ){
-    output_formatted(p, "/**** ERROR: (%d) %s *****/\n", rc,
-                sqlite3_errmsg(p->db));
+    char *zMsg = safeCommentText(sqlite3_errmsg(p->db));
+    output_formatted(p, "/**** ERROR: (%d) %s *****/\n", rc, zMsg);
+    sqlite3_free(zMsg);
     p->nErr++;
     return;
   }
@@ -591,8 +616,9 @@ static void output_sql_from_query(
   }
   rc = sqlite3_finalize(pSelect);
   if( rc!=SQLITE_OK ){
-    output_formatted(p, "/**** ERROR: (%d) %s *****/\n", rc,
-                     sqlite3_errmsg(p->db));
+    char *zMsg = safeCommentText(sqlite3_errmsg(p->db));
+    output_formatted(p, "/**** ERROR: (%d) %s *****/\n", rc, zMsg);
+    sqlite3_free(zMsg);
     if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
   }
 }
@@ -618,7 +644,9 @@ static void run_schema_dump_query(
   sqlite3_exec(p->db, z, dump_callback, p, &zErr);
   sqlite3_free(z);
   if( zErr ){
-    output_formatted(p, "/****** %s ******/\n", zErr);
+    char *zMsg = safeCommentText(zErr);
+    output_formatted(p, "/****** %s ******/\n", zMsg);
+    sqlite3_free(zMsg);
     sqlite3_free(zErr);
     p->nErr++;
     zErr = 0;
diff --git a/ext/recover/sqlite3recover.c b/ext/recover/sqlite3recover.c
index aa5ccc9..47a4b58 100644
--- a/ext/recover/sqlite3recover.c
+++ b/ext/recover/sqlite3recover.c
@@ -1280,9 +1280,19 @@ static int recoverWriteSchema2(sqlite3_recover *p){
   if( pSelect ){
     while( sqlite3_step(pSelect)==SQLITE_ROW ){
       const char *zSql = (const char*)sqlite3_column_text(pSelect, 1);
-      int rc = recoverOneStmt(p->dbOut, zSql, 0);
+      const char *zTail = 0;
+      int rc = recoverOneStmt(p->dbOut, zSql, &zTail);
       if( rc==SQLITE_OK ){
+        char *pToFree = 0;
+        if( zTail && zTail[0] ){
+          /* Omit any extraneous text that follows the first SQL statement */
+          int n = (int)(zTail - zSql);
+          while( n>0 && (zSql[n-1]==';' || zSql[n-1]<=' ') ){ n--; }
+          pToFree = sqlite3_mprintf("%.*s", n, zSql);
+          zSql = pToFree;
+        }
         recoverSqlCallback(p, zSql);
+        sqlite3_free(pToFree);
       }else if( rc!=SQLITE_ERROR ){
         recoverDbError(p, p->dbOut);
       }
diff --git a/src/shell.c.in b/src/shell.c.in
index d58587b..d4425fe 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -3234,6 +3234,30 @@ static void set_table_name(ShellState *p, const char 
*zName){
   shell_check_oom(p->zDestTable);
 }
 
+/*
+** Return a copy of the text z, obtained from sqlite3_malloc(), that is safe
+** to embed inside of a C-style comment in a script of SQL statements and
+** dot-commands.  Newlines and other control characters are changed to spaces,
+** and any end-of-comment sequence is broken up.  Otherwise, text taken from
+** an untrusted database (for example, a table name in an error message)
+** could terminate the comment and put arbitrary SQL, or a line that begins
+** with "." and so is interpreted as a dot-command, into the output.
+*/
+static char *shellSafeCommentText(const char *z){
+  char *zOut = sqlite3_mprintf("%s", z ? z : "");
+  int i;
+  if( zOut==0 ) return 0;
+  for(i=0; zOut[i]; i++){
+    unsigned char c = (unsigned char)zOut[i];
+    if( c<' ' || c==0x7f ){
+      zOut[i] = ' ';
+    }else if( c=='/' && i>0 && zOut[i-1]=='*' ){
+      zOut[i] = ' ';
+    }
+  }
+  return zOut;
+}
+
 /*
 ** Maybe construct two lines of text that point out the position of a
 ** syntax error.  Return a pointer to the text, in memory obtained from
@@ -3300,8 +3324,10 @@ static int run_table_dump_query(
   rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0);
   if( rc!=SQLITE_OK || !pSelect ){
     char *zContext = shell_error_context(zSelect, p->db);
+    char *zMsg = shellSafeCommentText(sqlite3_errmsg(p->db));
     cli_printf(p->out, "/**** ERROR: (%d) %s *****/\n%s",
-          rc, sqlite3_errmsg(p->db), zContext);
+          rc, zMsg, zContext);
+    sqlite3_free(zMsg);
     sqlite3_free(zContext);
     if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
     return rc;
@@ -3325,8 +3351,9 @@ static int run_table_dump_query(
   }
   rc = sqlite3_finalize(pSelect);
   if( rc!=SQLITE_OK ){
-    cli_printf(p->out, "/**** ERROR: (%d) %s *****/\n",
-                    rc, sqlite3_errmsg(p->db));
+    char *zMsg = shellSafeCommentText(sqlite3_errmsg(p->db));
+    cli_printf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, zMsg);
+    sqlite3_free(zMsg);
     if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++;
   }
   return rc;
@@ -4326,7 +4353,9 @@ static int run_schema_dump_query(
     int len = strlen30(zQuery);
     cli_puts("/****** CORRUPTION ERROR *******/\n", p->out);
     if( zErr ){
-      cli_printf(p->out, "/****** %s ******/\n", zErr);
+      char *zMsg = shellSafeCommentText(zErr);
+      cli_printf(p->out, "/****** %s ******/\n", zMsg);
+      sqlite3_free(zMsg);
       sqlite3_free(zErr);
       zErr = 0;
     }
@@ -4335,7 +4364,9 @@ static int run_schema_dump_query(
     sqlite3_snprintf(len+100, zQ2, "%s ORDER BY rowid DESC", zQuery);
     rc = sqlite3_exec(p->db, zQ2, dump_callback, p, &zErr);
     if( rc ){
-      cli_printf(p->out, "/****** ERROR: %s ******/\n", zErr);
+      char *zMsg = shellSafeCommentText(zErr);
+      cli_printf(p->out, "/****** ERROR: %s ******/\n", zMsg);
+      sqlite3_free(zMsg);
     }else{
       rc = SQLITE_CORRUPT;
     }
diff --git a/test/recover01.sql b/test/recover01.sql
index 416ebbe..caefd54 100644
--- a/test/recover01.sql
+++ b/test/recover01.sql
@@ -68,3 +68,75 @@ CREATE TABLE t1(a,b,c);
 PRAGMA writable_schema = off;
 COMMIT;
 **END-TEST**
+
+# Follow-up to f945de7c4eb73732.  The ".recover" command must also omit
+# extraneous text at the end of the sqlite_schema.sql field for views,
+# triggers, and non-unique indexes, not just for tables.
+#
+.open :memory:
+CREATE TABLE t1(a,b);
+CREATE INDEX i1 ON t1(a);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN SELECT 1; END;
+.dbconfig defensive off
+.dbconfig writable_schema on
+UPDATE sqlite_schema
+   SET sql=sql||';'||char(10)||'.print INJECTED_'||name
+ WHERE name IN ('i1','v1','r1');
+.testcase 410
+.recover
+.check --exact <<END
+.dbconfig defensive off
+.safe
+BEGIN;
+PRAGMA writable_schema = on;
+PRAGMA foreign_keys = off;
+PRAGMA encoding = 'UTF-8';
+PRAGMA page_size = '4096';
+PRAGMA auto_vacuum = '0';
+PRAGMA user_version = '0';
+PRAGMA application_id = '0';
+CREATE TABLE t1(a,b);
+CREATE INDEX i1 ON t1(a);
+CREATE VIEW v1 AS SELECT * FROM t1;
+CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN SELECT 1; END;
+PRAGMA writable_schema = off;
+COMMIT;
+END
+
+# The ".dump" command must not allow text from a malformed schema (which is
+# included in an error message that is output as an SQL comment) to escape
+# from the comment.  In this database the name of the only schema entry is
+# "x*/\n.print NAME_INJECTED\n/*" and its SQL is malformed.  (The first
+# three lines of expected output are an error message on stderr.)
+#
+.testcase 420
+.open --hexdb
+| size 1024 pagesize 512 filename unk.db
+| page 1 offset 0
+|     0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
+|    16: 02 00 01 01 00 40 20 20 00 00 00 02 00 00 00 02   .....@  ........
+|    32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04   ................
+|    48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
+|    80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02   ................
+|    96: 00 2e 9d 98 0d 00 00 00 01 01 c3 00 01 c3 00 00   ................
+|   448: 00 00 00 3b 01 06 17 43 11 01 31 74 61 62 6c 65   ...;...C..1table
+|   464: 78 2a 2f 0a 2e 70 72 69 6e 74 20 4e 41 4d 45 5f   x*/..print NAME_
+|   480: 49 4e 4a 45 43 54 45 44 0a 2f 2a 74 31 02 43 52   INJECTED./*t1.CR
+|   496: 45 41 54 45 20 54 41 42 4c 45 20 6a 75 6e 6b 28   EATE TABLE junk(
+| page 2 offset 512
+|     0: 0d 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00   ................
+| end unk.db
+.dump
+.check --exact <<END
+sql error: malformed database schema (x*/
+.print NAME_INJECTED
+/*) (11)
+PRAGMA foreign_keys=OFF;
+BEGIN TRANSACTION;
+/****** CORRUPTION ERROR *******/
+/****** malformed database schema (x*  .print NAME_INJECTED /*) ******/
+/****** ERROR: near "ORDER": syntax error ******/
+/**** ERROR: (11) malformed database schema (x*  .print NAME_INJECTED /*) 
*****/
+COMMIT;
+END

++++++ sqlite-3.54.1-CVE-2026-119586-recover-safe-mode.patch ++++++
From: drh <[email protected]>
Date: Wed, 11 Nov 2026 11:39:58 +0000
Subject: [PATCH] Add the ".safe" command to the CLI and enhance the
 ".recover" command so that the script it generates includes the ".safe"
 command near the top.

Prior check-in d684ccc9ec4e41d8 is sufficient to block the attack
described by CVE-2026-119586 (bsc#1289174).  This check-in simply
adds an additional layer of defense.  The new "--unsafe" option of
".recover" omits the ".safe" line from the output.

Upstream check-in: f2be7c2a98f2dc65
https://sqlite.org/src/info/f2be7c2a98f2dc65
Bug report: https://sqlite.org/bugs/forumpost/7e596d7ad7152f68

Backport notes: the upstream test changes to test/misc01.sql are
applied to test/recover01.sql instead (added by the previous patch).
Changes to the Fossil manifest files were dropped.

diff --git a/src/shell.c.in b/src/shell.c.in
index 365fcb0..d9f81b9 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -4536,9 +4536,13 @@ static const char *(azHelp[]) = {
   "   --lost-and-found TABLE   Alternative name for the lost-and-found table",
   "   --no-rowids              Do not attempt to recover rowid values",
   "                            that are not also INTEGER PRIMARY KEYs",
+  "   --unsafe                 Do not issue the \".safe\" command in output",
 #endif
 #ifndef SQLITE_SHELL_FIDDLE
   ".restore ?DB? FILE       Restore content of DB (default \"main\") from 
FILE",
+#endif
+  ".safe                    Put the CLI into \"safe mode\"",
+#ifndef SQLITE_SHELL_FIDDLE
   ".save ?OPTIONS? FILE     Write database to FILE (an alias for .backup ...)",
 #endif
   ".scanstats on|off|est    Turn sqlite3_stmt_scanstatus() metrics on or off",
@@ -7902,6 +7906,7 @@ static int recoverDatabaseCmd(ShellState *pState, int 
nArg, char **azArg){
   const char *zLAF = "lost_and_found";
   int bFreelist = 1;              /* 0 if --ignore-freelist is specified */
   int bRowids = 1;                /* 0 if --no-rowids */
+  int bUnsafe = 0;                /* 1 if --unsafe */
   sqlite3_recover *p = 0;
   int i = 0;
 
@@ -7928,6 +7933,9 @@ static int recoverDatabaseCmd(ShellState *pState, int 
nArg, char **azArg){
     }else
     if( n<=10 && memcmp("-no-rowids", z, n)==0 ){
       bRowids = 0;
+    }else
+    if( n<=7 && memcmp("-unsafe", z, n)==0 ){
+      bUnsafe = 1;
     }
     else{
       cli_printf(stderr,"unexpected option: %s\n", azArg[i]);
@@ -7948,6 +7956,7 @@ static int recoverDatabaseCmd(ShellState *pState, int 
nArg, char **azArg){
   sqlite3_recover_config(p, SQLITE_RECOVER_FREELIST_CORRUPT,(void*)&bFreelist);
 
   cli_printf(pState->out, ".dbconfig defensive off\n");
+  if( !bUnsafe ) cli_printf(pState->out, ".safe\n");
   sqlite3_recover_run(p);
   if( sqlite3_recover_errcode(p)!=SQLITE_OK ){
     const char *zErr = sqlite3_recover_errmsg(p);
@@ -9990,6 +9999,42 @@ static int dotCmdTestcase(ShellState *p){
   return 0;
 }
 
+
+/*
+** DOT-COMMAND: .safe
+** USAGE: .safe
+**
+** This command puts the CLI into "safe mode".  This command cannot be
+** undone.  The only way to restore full capabilities is to exit and
+** restart the CLI.
+**
+** Safe mode restricts SQL statements and dot-commands so that no
+** changes may be made to the filesystem other than writing to database
+** files that are already open.
+**
+**    *  The .open command is blocked unless the database is ":memory:"
+**       or the --hexdb option is used.
+**    *  The ATTACH command of SQL may not be used
+**    *  SQL functions with side effects (ex: writefile()) are blocked.
+**    *  The ".shell" and ".system" dot-commands are blocked.
+**    *  Dot-command like ".archive", ".backup", ".load", ".log", ".save"
+**       are blocked.
+**    *  Other commands with deleterious side effects are blocked.
+**
+** Unsafe actions might be simply blocked, or the CLI might issue an error
+** and exit immediately.
+**
+** CAUTION: If third-party extensions that have system side effects have
+** been loaded prior to the .safe command, the CLI has no knowledge of
+** those extensions and does not know to block them.  Unsafe actions might
+** still be possible using those third-party extension.
+*/
+static int dotCmdSafe(ShellState *p){
+  p->bSafeMode = 1;
+  p->bSafeModePersist = 1;
+  return 0;
+}
+
 /*
 ** Enlarge the space allocated in p->dot so that it can hold more
 ** than nArg parsed command-line arguments.
@@ -10004,7 +10049,6 @@ static void parseDotRealloc(ShellState *p, int nArg){
   shell_check_oom(p->dot.abQuot);
 }
 
-
 /*
 ** Parse input line zLine up into individual arguments.  Retain the
 ** parse in the p->dot substructure.
@@ -11774,6 +11818,10 @@ static int do_meta_command(const char *zLine, 
ShellState *p){
   }else
 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
 
+  if( c=='s' && cli_strcmp(azArg[0], "safe")==0 ){
+    rc = dotCmdSafe(p);
+  }else
+
   if( c=='s' &&
      (cli_strncmp(azArg[0], "scanstats",  n)==0 ||
       cli_strncmp(azArg[0], "scanstatus", n)==0)
diff --git a/test/recover.test b/test/recover.test
index 7035e40..5529a52 100644
--- a/test/recover.test
+++ b/test/recover.test
@@ -47,8 +47,8 @@ proc recover_with_opts {opts} {
   set sql [read $fd]
   close $fd
 
-  # Remove the ".dbconfig defensive off" line
-  set sql [string map {".dbconfig defensive off" ""} $sql]
+  # Remove the ".dbconfig defensive off" and ".safe" lines
+  set sql [string map {".dbconfig defensive off" "" ".safe" ""} $sql]
 
   forcedelete test.db2
   sqlite3 db2 test.db2
diff --git a/test/recover01.sql b/test/recover01.sql
index d4684cb..416ebbe 100644
--- a/test/recover01.sql
+++ b/test/recover01.sql
@@ -37,8 +37,9 @@
 |      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
 | end unk.db
 .recover
-.check <<END
+.check <<**END-TEST**
 .dbconfig defensive off
+.safe
 BEGIN;
 PRAGMA writable_schema = on;
 PRAGMA foreign_keys = off;
@@ -50,4 +51,20 @@ PRAGMA application_id = '0';
 CREATE TABLE t1(a,b,c);
 PRAGMA writable_schema = off;
 COMMIT;
-END
+**END-TEST**
+.testcase 401
+.recover --unsafe
+.check <<**END-TEST**
+.dbconfig defensive off
+BEGIN;
+PRAGMA writable_schema = on;
+PRAGMA foreign_keys = off;
+PRAGMA encoding = 'UTF-8';
+PRAGMA page_size = '4096';
+PRAGMA auto_vacuum = '0';
+PRAGMA user_version = '0';
+PRAGMA application_id = '0';
+CREATE TABLE t1(a,b,c);
+PRAGMA writable_schema = off;
+COMMIT;
+**END-TEST**

++++++ sqlite-3.54.1-CVE-2026-119586-recover-strip-trailing-sql.patch ++++++
From: drh <[email protected]>
Date: Fri, 6 Nov 2026 13:22:44 +0000
Subject: [PATCH] The .recover command now omits extraneous text found at the
 end of the sqlite_schema.sql field.

CVE-2026-119586 (bsc#1289174): the ".recover" command of the CLI
copied the sqlite_schema.sql values of the corrupt database verbatim
into its output.  A crafted value such as
"CREATE TABLE x(a);\n.shell touch /tmp/pwned" passes the
"sql GLOB 'CREATE *'" filter, and the embedded dot-command is then
executed when the output is piped into another sqlite3 process, as in
the documented idiom "sqlite3 corrupt.db .recover | sqlite3 new.db".

Only emit the first SQL statement of each schema entry and drop
any trailing text.

Upstream check-in: d684ccc9ec4e41d8
https://sqlite.org/src/info/d684ccc9ec4e41d8
Bug report: https://sqlite.org/bugs/forumpost/7e596d7ad7152f68

Backport notes: the upstream test case was added to test/misc01.sql,
which does not exist in 3.54.1; it is carried in a new file
test/recover01.sql which is run from test/shellB.test.  Changes to
the Fossil manifest files were dropped.

diff --git a/ext/recover/sqlite3recover.c b/ext/recover/sqlite3recover.c
index eedf178..aa5ccc9 100644
--- a/ext/recover/sqlite3recover.c
+++ b/ext/recover/sqlite3recover.c
@@ -539,11 +539,11 @@ static void recoverFinalize(sqlite3_recover *p, 
sqlite3_stmt *pStmt){
 ** Return the sqlite3_finalizer() or sqlite3_prepare() result code
 ** from running the zSql statement.
 */
-static int recoverOneStmt(sqlite3 *db, const char *zSql){
+static int recoverOneStmt(sqlite3 *db, const char *zSql, const char **pzTail){
   sqlite3_stmt *pStmt = 0;
   int rc;
   if( zSql==0 ) return SQLITE_OK;
-  rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
+  rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, pzTail);
   if( rc ){
     sqlite3_finalize(pStmt);
     return rc;
@@ -564,7 +564,7 @@ static int recoverOneStmt(sqlite3 *db, const char *zSql){
 */
 static int recoverExec(sqlite3_recover *p, sqlite3 *db, const char *zSql){
   if( p->errCode==SQLITE_OK ){
-    int rc = recoverOneStmt(db, zSql);
+    int rc = recoverOneStmt(db, zSql, 0);
     if( rc ){
       recoverDbError(p, db);
     }
@@ -1211,6 +1211,7 @@ static int recoverWriteSchema1(sqlite3_recover *p){
       const char *zSql = (const char*)sqlite3_column_text(pSelect, 4);
       char *zFree = 0;
       int rc = SQLITE_OK;
+      const char *zTail = 0;
 
       if( bVirtual ){
         zSql = (const char*)(zFree = recoverMPrintf(p,
@@ -1218,8 +1219,16 @@ static int recoverWriteSchema1(sqlite3_recover *p){
             zName, zName, zSql
         ));
       }
-      rc = recoverOneStmt(p->dbOut, zSql);
+      rc = recoverOneStmt(p->dbOut, zSql, &zTail);
       if( rc==SQLITE_OK ){
+        char *pToFree = 0;
+        if( zTail && zTail[0] ){
+          int n = (int)(zTail - zSql);
+          while( n>0 && (zSql[n-1]==';' || zSql[n-1]<=' ') ){ n--; }
+          pToFree = sqlite3_mprintf("%.*s", n, zSql);
+          zSql = pToFree;
+         
+        }
         recoverSqlCallback(p, zSql);
         if( bTable && !bVirtual ){
           if( SQLITE_ROW==sqlite3_step(pTblname) ){
@@ -1228,6 +1237,7 @@ static int recoverWriteSchema1(sqlite3_recover *p){
           }
           recoverReset(p, pTblname);
         }
+        sqlite3_free(pToFree);
       }else if( rc!=SQLITE_ERROR ){
         recoverDbError(p, p->dbOut);
       }
@@ -1270,7 +1280,7 @@ static int recoverWriteSchema2(sqlite3_recover *p){
   if( pSelect ){
     while( sqlite3_step(pSelect)==SQLITE_ROW ){
       const char *zSql = (const char*)sqlite3_column_text(pSelect, 1);
-      int rc = recoverOneStmt(p->dbOut, zSql);
+      int rc = recoverOneStmt(p->dbOut, zSql, 0);
       if( rc==SQLITE_OK ){
         recoverSqlCallback(p, zSql);
       }else if( rc!=SQLITE_ERROR ){
@@ -2648,7 +2658,7 @@ static void recoverStep(sqlite3_recover *p){
           if( bUseWrapper ) recoverUninstallWrapper(p);
         }while( p->errCode==SQLITE_NOTADB 
              && (bUseWrapper--) 
-             && SQLITE_OK==recoverOneStmt(p->dbIn, "ROLLBACK")
+             && SQLITE_OK==recoverOneStmt(p->dbIn, "ROLLBACK", 0)
         );
       }
 
@@ -2713,7 +2723,7 @@ static void recoverStep(sqlite3_recover *p){
       ** database. Regardless of whether or not an error has occurred, make
       ** an attempt to end the read transaction on the input database.  */
       recoverExec(p, p->dbOut, "COMMIT");
-      rc = recoverOneStmt(p->dbIn, "END");
+      rc = recoverOneStmt(p->dbIn, "END", 0);
       if( p->errCode==SQLITE_OK ) p->errCode = rc;
 
       recoverSqlCallback(p, "PRAGMA writable_schema = off");
@@ -2909,7 +2919,7 @@ int sqlite3_recover_finish(sqlite3_recover *p){
   }else{
     recoverFinalCleanup(p);
     if( p->bCloseTransaction && sqlite3_get_autocommit(p->dbIn)==0 ){
-      rc = recoverOneStmt(p->dbIn, "END");
+      rc = recoverOneStmt(p->dbIn, "END", 0);
       if( p->errCode==SQLITE_OK ) p->errCode = rc;
     }
     rc = p->errCode;
diff --git a/test/recover01.sql b/test/recover01.sql
new file mode 100644
index 0000000..d4684cb
--- /dev/null
+++ b/test/recover01.sql
@@ -0,0 +1,53 @@
+#!sqlite3
+#
+# 2026-11-06
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# Test cases for the ".recover" command of the CLI.
+#
+# Backported from upstream test/misc01.sql.
+#
+
+# f945de7c4eb73732 2026-11-06T04:16:54Z
+# sqlite3's .recover output can smuggle shell commands into the next
+# sqlite3 run
+#
+.testcase 400
+.open --hexdb
+| size 8192 pagesize 4096 filename unk.db
+| page 1 offset 0
+|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
+|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 02   .....@  ........
+|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04   ................
+|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
+|     96: 00 00 00 00 0d 00 00 00 01 0f ca 00 0f ca 00 00   ................
+|   4032: 00 00 00 00 00 00 00 00 00 00 34 01 06 17 11 11   ..........4.....
+|   4048: 01 55 74 61 62 6c 65 74 31 74 31 02 43 52 45 41   .Utablet1t1.CREA
+|   4064: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 2c   TE TABLE t1(a,b,
+|   4080: 63 29 3b 0a 2e 70 72 69 6e 74 20 68 65 6c 6c 6f   c);..print hello
+| page 2 offset 4096
+|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
+| end unk.db
+.recover
+.check <<END
+.dbconfig defensive off
+BEGIN;
+PRAGMA writable_schema = on;
+PRAGMA foreign_keys = off;
+PRAGMA encoding = 'UTF-8';
+PRAGMA page_size = '4096';
+PRAGMA auto_vacuum = '0';
+PRAGMA user_version = '0';
+PRAGMA application_id = '0';
+CREATE TABLE t1(a,b,c);
+PRAGMA writable_schema = off;
+COMMIT;
+END
diff --git a/test/shellB.test b/test/shellB.test
index 1481c86..a175e3e 100644
--- a/test/shellB.test
+++ b/test/shellB.test
@@ -78,6 +78,7 @@ ifcapable vtab {
   do_clitest dotcmd01.sql
   do_clitest import01.sql
   do_clitest intck01.sql --unsafe-testing
+  do_clitest recover01.sql
 }
 do_clitest fptest01.sql
 unset -nocomplain ::env(SQLITE_PS1)

++++++ sqlite-3.54.1-CVE-2026-119586-safe-mode-hardening.patch ++++++
From: drh <[email protected]>
Date: Wed, 11 Nov 2026 12:32:27 +0000
Subject: [PATCH] Further strengthening of the new ".safe" command in the CLI.

When ".safe" is issued, unregister the writefile() and zipfile()
functions and the fsdir and zipfile virtual tables from all databases
that are already open, so that they cannot be used to write files.
Also document that safe mode does not protect database files that are
already open.

Follow-up hardening for CVE-2026-119586 (bsc#1289174).

Upstream check-in: d486e997908bbd1b
https://sqlite.org/src/info/d486e997908bbd1b

Backport notes: changes to the Fossil manifest files were dropped.

diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c
index eafade0..49e853a 100644
--- a/ext/misc/fileio.c
+++ b/ext/misc/fileio.c
@@ -1271,6 +1271,10 @@ int sqlite3_fileio_init(
   int rc = SQLITE_OK;
   SQLITE_EXTENSION_INIT2(pApi);
   (void)pzErrMsg;  /* Unused parameter */
+
+  /* REMINDER: Changes here should be reflected in the ".safe" command
+  ** of the CLI.
+  */
   rc = sqlite3_create_function(db, "readfile", 1, 
                                SQLITE_UTF8|SQLITE_DIRECTONLY, 0,
                                readfileFunc, 0, 0);
diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c
index edcdc6a..8591aed 100644
--- a/ext/misc/zipfile.c
+++ b/ext/misc/zipfile.c
@@ -2271,6 +2271,9 @@ static int zipfileRegister(sqlite3 *db){
     0                          /* xIntegrity */
   };
 
+  /* REMINDER: Changes here should also be reflected in the ".safe"
+  ** command of the CLI
+  */
   int rc = sqlite3_create_module(db, "zipfile"  , &zipfileModule, 0);
   if( rc==SQLITE_OK ) rc = sqlite3_overload_function(db, "zipfile_cds", -1);
   if( rc==SQLITE_OK ){
diff --git a/src/shell.c.in b/src/shell.c.in
index d9f81b9..d58587b 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -10024,14 +10024,28 @@ static int dotCmdTestcase(ShellState *p){
 ** Unsafe actions might be simply blocked, or the CLI might issue an error
 ** and exit immediately.
 **
-** CAUTION: If third-party extensions that have system side effects have
-** been loaded prior to the .safe command, the CLI has no knowledge of
-** those extensions and does not know to block them.  Unsafe actions might
-** still be possible using those third-party extension.
+** Safe mode does not prevent harm to database files that are already open.
+** An attacker can still delete content and even use commands like
+** "PRAGMA writable_schema=ON" to corrupt a database file that is already
+** open.  Safe mode only blocks access to other previously unopened files.
+**
+** CAUTION: If third-party extensions with system side effects have been
+** loaded prior to the .safe command, the CLI has no knowledge of those
+** extensions and does not know to block them.  Unsafe actions might still
+** be possible using those third-party extension.
 */
 static int dotCmdSafe(ShellState *p){
+  int i;
   p->bSafeMode = 1;
   p->bSafeModePersist = 1;
+  for(i=0; i<ArraySize(p->aAuxDb); i++){
+    sqlite3 *db = p->aAuxDb[i].db;
+    if( db==0 ) continue;
+    sqlite3_create_module(db, "fsdir", 0, 0);
+    sqlite3_create_function(db, "writefile", -1, 0, 0, 0, 0, 0);
+    sqlite3_create_module(db, "zipfile", 0, 0);
+    sqlite3_create_function(db, "zipfile", -1, 0, 0, 0, 0, 0);
+  }
   return 0;
 }
 

Reply via email to