Skip to content

Commit 955decc

Browse files
committed
merge revision(s) beb85e7: [Backport #21705]
[PATCH] [Bug #21705] Fix segfaults on Windows It should check the type of the argument and coercion before converting the encoding.
1 parent fe8221a commit 955decc

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

ext/socket/unixsocket.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ unixsock_path_value(VALUE path)
4242
}
4343
}
4444
#endif
45+
path = rb_get_path(path);
4546
#ifdef _WIN32
4647
/* UNIXSocket requires UTF-8 per spec. */
4748
path = rb_str_export_to_enc(path, rb_utf8_encoding());
4849
#endif
49-
return rb_get_path(path);
50+
return path;
5051
}
5152

5253
VALUE

test/socket/test_unix.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,18 @@ def bound_unix_socket(klass)
292292
File.unlink path if path && File.socket?(path)
293293
end
294294

295-
def test_open_nul_byte
296-
tmpfile = Tempfile.new("s")
297-
path = tmpfile.path
298-
tmpfile.close(true)
299-
assert_raise(ArgumentError) {UNIXServer.open(path+"\0")}
300-
assert_raise(ArgumentError) {UNIXSocket.open(path+"\0")}
301-
ensure
302-
File.unlink path if path && File.socket?(path)
295+
def test_open_argument
296+
assert_raise(TypeError) {UNIXServer.new(nil)}
297+
assert_raise(TypeError) {UNIXServer.new(1)}
298+
Tempfile.create("s") do |s|
299+
path = s.path
300+
s.close
301+
File.unlink(path)
302+
assert_raise(ArgumentError) {UNIXServer.open(path+"\0")}
303+
assert_raise(ArgumentError) {UNIXSocket.open(path+"\0")}
304+
arg = Struct.new(:to_path).new(path)
305+
assert_equal(path, UNIXServer.open(arg) { |server| server.path })
306+
end
303307
end
304308

305309
def test_addr

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 7
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 67
14+
#define RUBY_PATCHLEVEL 68
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)