mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user