Skip to content

Commit

Permalink
Merge pull request #340 from sparklemotion/339-load-extension-segfault
Browse files Browse the repository at this point in the history
fix: Database#load_extension check argument type
  • Loading branch information
flavorjones authored Aug 28, 2022
2 parents 3126e73 + 31785dd commit e27f9b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ You can opt-out of the packaged version of sqlite (and use your system-installed
* `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).


### Fixed

* `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]


## 1.4.4 / 2022-06-14

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion ext/sqlite3/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ static VALUE load_extension(VALUE self, VALUE file)
Data_Get_Struct(self, sqlite3Ruby, ctx);
REQUIRE_OPEN_DB(ctx);

status = sqlite3_load_extension(ctx->db, RSTRING_PTR(file), 0, &errMsg);
status = sqlite3_load_extension(ctx->db, StringValuePtr(file), 0, &errMsg);
if (status != SQLITE_OK)
{
errexp = rb_exc_new2(rb_eRuntimeError, errMsg);
Expand Down
7 changes: 7 additions & 0 deletions test/test_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -534,5 +534,12 @@ def test_strict_mode
end
assert_includes error.message, "no such column: nope"
end

def test_load_extension_with_nonstring_argument
db = SQLite3::Database.new(':memory:')
skip("extensions are not enabled") unless db.respond_to?(:load_extension)
assert_raises(TypeError) { db.load_extension(1) }
assert_raises(TypeError) { db.load_extension(Pathname.new("foo.so")) }
end
end
end

0 comments on commit e27f9b0

Please sign in to comment.