about summary refs log tree commit homepage
diff options
context:
space:
mode:
-rw-r--r--ext/tdb/tdb.c2
-rw-r--r--test/test_tdb.rb4
2 files changed, 5 insertions, 1 deletions
diff --git a/ext/tdb/tdb.c b/ext/tdb/tdb.c
index a4a5ec5..0a0adf2 100644
--- a/ext/tdb/tdb.c
+++ b/ext/tdb/tdb.c
@@ -262,7 +262,7 @@ static VALUE init(int argc, VALUE *argv, VALUE self)
         if (NIL_P(path))
                 o.tdb_flags |= TDB_INTERNAL;
         else
-                o.name = StringValuePtr(path);
+                o.name = StringValueCStr(path);
 
         tdb = (struct tdb_context *)my_tbr(nogvl_open, &o);
         if (!tdb) {
diff --git a/test/test_tdb.rb b/test/test_tdb.rb
index 7ae581d..9b2ed71 100644
--- a/test/test_tdb.rb
+++ b/test/test_tdb.rb
@@ -16,6 +16,10 @@ class TestTdb < Test::Unit::TestCase
     @tdb.close if @tdb && ! @tdb.closed?
   end
 
+  def test_create_file_null_byte_in_path
+    assert_raises(ArgumentError) { TDB.new("hello.tdb\0") }
+  end
+
   def test_create_file
     assert_nothing_raised do
       @tmp = Tempfile.new('tdb')