diff options
| author | Eli Zaretskii | 2023-05-20 15:43:44 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2023-05-20 15:43:44 +0300 |
| commit | ead3a2abbfc347b0f562c1e051b370a0617ee8aa (patch) | |
| tree | 25633d5df72f473e681fc18d2ffb5fae66e0847e /src/sqlite.c | |
| parent | a6bddd176582f8bea79ec77e1e27bb583a6ef0b5 (diff) | |
| download | emacs-ead3a2abbfc347b0f562c1e051b370a0617ee8aa.tar.gz emacs-ead3a2abbfc347b0f562c1e051b370a0617ee8aa.zip | |
Fix loading SQLite extensions
* src/sqlite.c (sqlite3_db_config) [WINDOWSNT]: Load from the DLL.
(Fsqlite_load_extension): Use 'sqlite3_db_config' to enable and
disable loading of extensions. Add a few free extensions to the
allow-list. Fix testing for the ".dll" extension. (Bug#63590)
* test/src/sqlite-tests.el (sqlite-load-extension): Fix the test
to require successful load if the extension does exist.
Diffstat (limited to 'src/sqlite.c')
| -rw-r--r-- | src/sqlite.c | 53 |
1 files changed, 44 insertions, 9 deletions
diff --git a/src/sqlite.c b/src/sqlite.c index 0361514766a..77ce61ba657 100644 --- a/src/sqlite.c +++ b/src/sqlite.c | |||
| @@ -23,6 +23,8 @@ YOSHIDA <syohex@gmail.com>, which can be found at: | |||
| 23 | https://github.com/syohex/emacs-sqlite3 */ | 23 | https://github.com/syohex/emacs-sqlite3 */ |
| 24 | 24 | ||
| 25 | #include <config.h> | 25 | #include <config.h> |
| 26 | |||
| 27 | #include <c-strcase.h> | ||
| 26 | #include "lisp.h" | 28 | #include "lisp.h" |
| 27 | #include "coding.h" | 29 | #include "coding.h" |
| 28 | 30 | ||
| @@ -80,6 +82,9 @@ DEF_DLL_FN (SQLITE_API int, sqlite3_load_extension, | |||
| 80 | (sqlite3*, const char*, const char*, char**)); | 82 | (sqlite3*, const char*, const char*, char**)); |
| 81 | # undef sqlite3_load_extension | 83 | # undef sqlite3_load_extension |
| 82 | # define sqlite3_load_extension fn_sqlite3_load_extension | 84 | # define sqlite3_load_extension fn_sqlite3_load_extension |
| 85 | DEF_DLL_FN (SQLITE_API int, sqlite3_db_config, (sqlite3*, int, ...)); | ||
| 86 | # undef sqlite3_db_config | ||
| 87 | # define sqlite3_db_config fn_sqlite3_db_config | ||
| 83 | # endif | 88 | # endif |
| 84 | 89 | ||
| 85 | # undef sqlite3_finalize | 90 | # undef sqlite3_finalize |
| @@ -172,6 +177,7 @@ load_dll_functions (HMODULE library) | |||
| 172 | LOAD_DLL_FN (library, sqlite3_exec); | 177 | LOAD_DLL_FN (library, sqlite3_exec); |
| 173 | # ifdef HAVE_SQLITE3_LOAD_EXTENSION | 178 | # ifdef HAVE_SQLITE3_LOAD_EXTENSION |
| 174 | LOAD_DLL_FN (library, sqlite3_load_extension); | 179 | LOAD_DLL_FN (library, sqlite3_load_extension); |
| 180 | LOAD_DLL_FN (library, sqlite3_db_config); | ||
| 175 | # endif | 181 | # endif |
| 176 | LOAD_DLL_FN (library, sqlite3_prepare_v2); | 182 | LOAD_DLL_FN (library, sqlite3_prepare_v2); |
| 177 | return true; | 183 | return true; |
| @@ -684,9 +690,28 @@ Only modules on Emacs' list of allowed modules can be loaded. */) | |||
| 684 | CHECK_STRING (module); | 690 | CHECK_STRING (module); |
| 685 | 691 | ||
| 686 | /* Add names of useful and free modules here. */ | 692 | /* Add names of useful and free modules here. */ |
| 687 | const char *allowlist[3] = { "pcre", "csvtable", NULL }; | 693 | const char *allowlist[] = { |
| 694 | "base64", | ||
| 695 | "cksumvfs", | ||
| 696 | "compress", | ||
| 697 | "csv", | ||
| 698 | "csvtable", | ||
| 699 | "fts3", | ||
| 700 | "icu", | ||
| 701 | "pcre", | ||
| 702 | "percentile", | ||
| 703 | "regexp", | ||
| 704 | "rot13", | ||
| 705 | "rtree", | ||
| 706 | "sha1", | ||
| 707 | "uuid", | ||
| 708 | "vfslog", | ||
| 709 | "zipfile", | ||
| 710 | NULL | ||
| 711 | }; | ||
| 688 | char *name = SSDATA (Ffile_name_nondirectory (module)); | 712 | char *name = SSDATA (Ffile_name_nondirectory (module)); |
| 689 | /* Possibly skip past a common prefix. */ | 713 | /* Possibly skip past a common prefix (libsqlite3_mod_ is used by |
| 714 | Debian, see https://packages.debian.org/source/sid/sqliteodbc). */ | ||
| 690 | const char *prefix = "libsqlite3_mod_"; | 715 | const char *prefix = "libsqlite3_mod_"; |
| 691 | if (!strncmp (name, prefix, strlen (prefix))) | 716 | if (!strncmp (name, prefix, strlen (prefix))) |
| 692 | name += strlen (prefix); | 717 | name += strlen (prefix); |
| @@ -697,7 +722,7 @@ Only modules on Emacs' list of allowed modules can be loaded. */) | |||
| 697 | if (strlen (*allow) < strlen (name) | 722 | if (strlen (*allow) < strlen (name) |
| 698 | && !strncmp (*allow, name, strlen (*allow)) | 723 | && !strncmp (*allow, name, strlen (*allow)) |
| 699 | && (!strcmp (name + strlen (*allow), ".so") | 724 | && (!strcmp (name + strlen (*allow), ".so") |
| 700 | || !strcmp (name + strlen (*allow), ".DLL"))) | 725 | || !strcasecmp (name + strlen (*allow), ".dll"))) |
| 701 | { | 726 | { |
| 702 | do_allow = true; | 727 | do_allow = true; |
| 703 | break; | 728 | break; |
| @@ -707,12 +732,22 @@ Only modules on Emacs' list of allowed modules can be loaded. */) | |||
| 707 | if (!do_allow) | 732 | if (!do_allow) |
| 708 | xsignal1 (Qsqlite_error, build_string ("Module name not on allowlist")); | 733 | xsignal1 (Qsqlite_error, build_string ("Module name not on allowlist")); |
| 709 | 734 | ||
| 710 | int result = sqlite3_load_extension | 735 | /* Expand all Lisp data explicitly, so as to avoid signaling an |
| 711 | (XSQLITE (db)->db, | 736 | error while extension loading is enabled -- we don't want to |
| 712 | SSDATA (ENCODE_FILE (Fexpand_file_name (module, Qnil))), | 737 | "leak" this outside this function. */ |
| 713 | NULL, NULL); | 738 | sqlite3 *sdb = XSQLITE (db)->db; |
| 714 | if (result == SQLITE_OK) | 739 | char *ext_fn = SSDATA (ENCODE_FILE (Fexpand_file_name (module, Qnil))); |
| 715 | return Qt; | 740 | /* Temporarily enable loading extensions via the C API. */ |
| 741 | int result = sqlite3_db_config (sdb, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, | ||
| 742 | NULL); | ||
| 743 | if (result == SQLITE_OK) | ||
| 744 | { | ||
| 745 | result = sqlite3_load_extension (sdb, ext_fn, NULL, NULL); | ||
| 746 | /* Disable loading extensions via C API. */ | ||
| 747 | sqlite3_db_config (sdb, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 0, NULL); | ||
| 748 | if (result == SQLITE_OK) | ||
| 749 | return Qt; | ||
| 750 | } | ||
| 716 | return Qnil; | 751 | return Qnil; |
| 717 | } | 752 | } |
| 718 | #endif /* HAVE_SQLITE3_LOAD_EXTENSION */ | 753 | #endif /* HAVE_SQLITE3_LOAD_EXTENSION */ |