Skip to content

Commit 7085db4

Browse files
committed
file.c: poisoned NUL
* file.c (rb_get_path_check): path name must not contain NUL bytes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 84fa14a commit 7085db4

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Fri Oct 12 18:18:03 2012 Nobuyoshi Nakada <[email protected]>
2+
3+
* file.c (rb_get_path_check): path name must not contain NUL bytes.
4+
15
Fri Oct 12 16:06:20 2012 NAKAMURA Usaku <[email protected]>
26

37
* tool/merger.rb: now can merge revision(s) without --ticket again.

file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ rb_get_path_check(VALUE obj, int level)
184184
rb_raise(rb_eEncCompatError, "path name must be ASCII-compatible (%s): %s",
185185
rb_enc_name(enc), RSTRING_PTR(tmp));
186186
}
187+
188+
StringValueCStr(tmp);
189+
187190
return rb_str_new4(tmp);
188191
}
189192

test/ruby/test_file.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,14 @@ def test_long_unc
349349
end
350350
end
351351
end
352+
353+
def test_open_nul
354+
Dir.mktmpdir(__method__.to_s) do |tmpdir|
355+
path = File.join(tmpdir, "foo")
356+
assert_raise(ArgumentError) do
357+
open(path + "\0bar", "w") {}
358+
end
359+
assert_file_not(:exist?, path)
360+
end
361+
end
352362
end

0 commit comments

Comments
 (0)