https://github.com/syohex/emacs-sqlite3 */
#include <config.h>
+
+#include <c-strcase.h>
#include "lisp.h"
#include "coding.h"
(sqlite3*, const char*, const char*, char**));
# undef sqlite3_load_extension
# define sqlite3_load_extension fn_sqlite3_load_extension
+DEF_DLL_FN (SQLITE_API int, sqlite3_db_config, (sqlite3*, int, ...));
+# undef sqlite3_db_config
+# define sqlite3_db_config fn_sqlite3_db_config
# endif
# undef sqlite3_finalize
LOAD_DLL_FN (library, sqlite3_exec);
# ifdef HAVE_SQLITE3_LOAD_EXTENSION
LOAD_DLL_FN (library, sqlite3_load_extension);
+ LOAD_DLL_FN (library, sqlite3_db_config);
# endif
LOAD_DLL_FN (library, sqlite3_prepare_v2);
return true;
CHECK_STRING (module);
/* Add names of useful and free modules here. */
- const char *allowlist[3] = { "pcre", "csvtable", NULL };
+ const char *allowlist[] = {
+ "base64",
+ "cksumvfs",
+ "compress",
+ "csv",
+ "csvtable",
+ "fts3",
+ "icu",
+ "pcre",
+ "percentile",
+ "regexp",
+ "rot13",
+ "rtree",
+ "sha1",
+ "uuid",
+ "vfslog",
+ "zipfile",
+ NULL
+ };
char *name = SSDATA (Ffile_name_nondirectory (module));
- /* Possibly skip past a common prefix. */
+ /* Possibly skip past a common prefix (libsqlite3_mod_ is used by
+ Debian, see https://packages.debian.org/source/sid/sqliteodbc). */
const char *prefix = "libsqlite3_mod_";
if (!strncmp (name, prefix, strlen (prefix)))
name += strlen (prefix);
if (strlen (*allow) < strlen (name)
&& !strncmp (*allow, name, strlen (*allow))
&& (!strcmp (name + strlen (*allow), ".so")
- || !strcmp (name + strlen (*allow), ".DLL")))
+ || !strcasecmp (name + strlen (*allow), ".dll")))
{
do_allow = true;
break;
if (!do_allow)
xsignal1 (Qsqlite_error, build_string ("Module name not on allowlist"));
- int result = sqlite3_load_extension
- (XSQLITE (db)->db,
- SSDATA (ENCODE_FILE (Fexpand_file_name (module, Qnil))),
- NULL, NULL);
- if (result == SQLITE_OK)
- return Qt;
+ /* Expand all Lisp data explicitly, so as to avoid signaling an
+ error while extension loading is enabled -- we don't want to
+ "leak" this outside this function. */
+ sqlite3 *sdb = XSQLITE (db)->db;
+ char *ext_fn = SSDATA (ENCODE_FILE (Fexpand_file_name (module, Qnil)));
+ /* Temporarily enable loading extensions via the C API. */
+ int result = sqlite3_db_config (sdb, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1,
+ NULL);
+ if (result == SQLITE_OK)
+ {
+ result = sqlite3_load_extension (sdb, ext_fn, NULL, NULL);
+ /* Disable loading extensions via C API. */
+ sqlite3_db_config (sdb, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 0, NULL);
+ if (result == SQLITE_OK)
+ return Qt;
+ }
return Qnil;
}
#endif /* HAVE_SQLITE3_LOAD_EXTENSION */
(sqlite-load-extension db "/usr/lib/sqlite3/"))
(should-error
(sqlite-load-extension db "/usr/lib/sqlite3"))
- (should
- (memq
- (sqlite-load-extension db "/usr/lib/sqlite3/pcre.so")
- '(nil t)))
+ (if (eq system-type 'windows-nt)
+ (should
+ (eq (sqlite-load-extension db "/usr/lib/sqlite3/pcre.dll")
+ (file-readable-p "/usr/lib/sqlite3/pcre.dll")))
+ (should
+ (eq (sqlite-load-extension db "/usr/lib/sqlite3/pcre.so")
+ (file-readable-p "/usr/lib/sqlite3/pcre.so"))))
(should-error
(sqlite-load-extension
(should-error
(sqlite-load-extension
db "/usr/lib/x86_64-linux-gnu/libsqlite3_mod_csvtable"))
- (should
- (memq
- (sqlite-load-extension
- db "/usr/lib/x86_64-linux-gnu/libsqlite3_mod_csvtable.so")
- '(nil t)))))
+ (if (eq system-type 'windows-nt)
+ (should
+ (eq (sqlite-load-extension db "/usr/lib/sqlite3/csvtable.dll")
+ (file-readable-p "/usr/lib/sqlite3/csvtable.dll")))
+ (should
+ (eq (sqlite-load-extension db "/usr/lib/x86_64-linux-gnu/libsqlite3_mod_csvtable.so")
+ (file-readable-p "/usr/lib/x86_64-linux-gnu/libsqlite3_mod_csvtable.so"))))))
(ert-deftest sqlite-blob ()
(skip-unless (sqlite-available-p))