Skip to content

Commit 31785dd

Browse files
committed
fix: Database#load_extension check argument type
and raise TypeError if it's not a String Fixes sparklemotion#339
1 parent 3126e73 commit 31785dd

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ You can opt-out of the packaged version of sqlite (and use your system-installed
4444
* `SQLite3::SQLITE_LOADED_VERSION` contains the version string of the sqlite3 library that is dynamically loaded (compare to `SQLite3::SQLITE_VERSION` which is the version at compile-time).
4545

4646

47+
### Fixed
48+
49+
* `SQLite3::Database#load_extensions` now raises a `TypeError` unless a String is passed as the file path. Previously it was possible to pass a non-string and cause a segfault. [#339]
50+
51+
4752
## 1.4.4 / 2022-06-14
4853

4954
### Fixes

ext/sqlite3/database.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ static VALUE load_extension(VALUE self, VALUE file)
603603
Data_Get_Struct(self, sqlite3Ruby, ctx);
604604
REQUIRE_OPEN_DB(ctx);
605605

606-
status = sqlite3_load_extension(ctx->db, RSTRING_PTR(file), 0, &errMsg);
606+
status = sqlite3_load_extension(ctx->db, StringValuePtr(file), 0, &errMsg);
607607
if (status != SQLITE_OK)
608608
{
609609
errexp = rb_exc_new2(rb_eRuntimeError, errMsg);

test/test_database.rb

+7
Original file line numberDiff line numberDiff line change
@@ -534,5 +534,12 @@ def test_strict_mode
534534
end
535535
assert_includes error.message, "no such column: nope"
536536
end
537+
538+
def test_load_extension_with_nonstring_argument
539+
db = SQLite3::Database.new(':memory:')
540+
skip("extensions are not enabled") unless db.respond_to?(:load_extension)
541+
assert_raises(TypeError) { db.load_extension(1) }
542+
assert_raises(TypeError) { db.load_extension(Pathname.new("foo.so")) }
543+
end
537544
end
538545
end

0 commit comments

Comments
 (0)