aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Liz <accs@liz3.net> 2023-09-21 08:43:21 +0200
committerGravatar GitHub <noreply@github.com> 2023-09-20 23:43:21 -0700
commit2664dfad9bb0b2d83bf64ebda5b7e512b89f5e91 (patch)
tree4f51afeccdf2963315e82a6998cc2bce505642c6
parente0c5debc5749a38ed4699f8c02333df22046ee9b (diff)
downloadbun-2664dfad9bb0b2d83bf64ebda5b7e512b89f5e91.tar.gz
bun-2664dfad9bb0b2d83bf64ebda5b7e512b89f5e91.tar.zst
bun-2664dfad9bb0b2d83bf64ebda5b7e512b89f5e91.zip
fix: add check to sqlite extension loading logic (#5773)
The sqlite3 logic to dynamically load extensions can be disabled to save space, which macos does by default. sqlite3 provides a api to check for these compile time settings at runtime, we can use that to throw a js error rather then crashing. It is worth noting though that the api to check for these settings at runtime itself can be disabled through SQLITE_OMIT_COMPILEOPTION_DIAGS but this seams to be a edge case.
-rw-r--r--src/bun.js/bindings/sqlite/JSSQLStatement.cpp5
-rw-r--r--src/bun.js/bindings/sqlite/lazy_sqlite3.h4
2 files changed, 9 insertions, 0 deletions
diff --git a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
index e36d2b809..72c7d9a07 100644
--- a/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
+++ b/src/bun.js/bindings/sqlite/JSSQLStatement.cpp
@@ -695,6 +695,11 @@ JSC_DEFINE_HOST_FUNCTION(jsSQLStatementLoadExtensionFunction, (JSC::JSGlobalObje
return JSValue::encode(JSC::jsUndefined());
}
+ if(sqlite3_compileoption_used("SQLITE_OMIT_LOAD_EXTENSION")) {
+ throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "This build of sqlite3 does not support dynamic extension loading"_s));
+ return JSValue::encode(JSC::jsUndefined());
+ }
+
auto entryPointStr = callFrame->argumentCount() > 2 && callFrame->argument(2).isString() ? callFrame->argument(2).toWTFString(lexicalGlobalObject) : String();
const char* entryPoint = entryPointStr.length() == 0 ? NULL : entryPointStr.utf8().data();
char* error;
diff --git a/src/bun.js/bindings/sqlite/lazy_sqlite3.h b/src/bun.js/bindings/sqlite/lazy_sqlite3.h
index 8b23a7e03..a012f6ab6 100644
--- a/src/bun.js/bindings/sqlite/lazy_sqlite3.h
+++ b/src/bun.js/bindings/sqlite/lazy_sqlite3.h
@@ -71,6 +71,7 @@ typedef int (*lazy_sqlite3_deserialize_type)(
);
typedef int (*lazy_sqlite3_stmt_readonly_type)(sqlite3_stmt* pStmt);
+typedef int (*lazy_sqlite3_compileoption_used_type)(const char *zOptName);
static lazy_sqlite3_bind_blob_type lazy_sqlite3_bind_blob;
static lazy_sqlite3_bind_double_type lazy_sqlite3_bind_double;
@@ -112,6 +113,7 @@ static lazy_sqlite3_malloc64_type lazy_sqlite3_malloc64;
static lazy_sqlite3_serialize_type lazy_sqlite3_serialize;
static lazy_sqlite3_deserialize_type lazy_sqlite3_deserialize;
static lazy_sqlite3_stmt_readonly_type lazy_sqlite3_stmt_readonly;
+static lazy_sqlite3_compileoption_used_type lazy_sqlite3_compileoption_used;
#define sqlite3_bind_blob lazy_sqlite3_bind_blob
#define sqlite3_bind_double lazy_sqlite3_bind_double
@@ -152,6 +154,7 @@ static lazy_sqlite3_stmt_readonly_type lazy_sqlite3_stmt_readonly;
#define sqlite3_deserialize lazy_sqlite3_deserialize
#define sqlite3_stmt_readonly lazy_sqlite3_stmt_readonly
#define sqlite3_column_int64 lazy_sqlite3_column_int64
+#define sqlite3_compileoption_used lazy_sqlite3_compileoption_used;
static void* sqlite3_handle = nullptr;
static const char* sqlite3_lib_path = "libsqlite3.dylib";
@@ -204,6 +207,7 @@ static int lazyLoadSQLite()
lazy_sqlite3_deserialize = (lazy_sqlite3_deserialize_type)dlsym(sqlite3_handle, "sqlite3_deserialize");
lazy_sqlite3_malloc64 = (lazy_sqlite3_malloc64_type)dlsym(sqlite3_handle, "sqlite3_malloc64");
lazy_sqlite3_stmt_readonly = (lazy_sqlite3_stmt_readonly_type)dlsym(sqlite3_handle, "sqlite3_stmt_readonly");
+ lazy_sqlite3_compileoption_used = (lazy_sqlite3_compileoption_used_type)dlsym(sqlite3_handle, "sqlite3_compileoption_used");
return 0;
}