summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2025-11-30 10:36:56 +0900
committernagachika <nagachika@ruby-lang.org>2025-11-30 10:36:56 +0900
commit1974ccabbfdc73e78e758a6ad7ea8542e2119432 (patch)
treebfc903f3457c0ee1fa01b5d6c36558e4492b77ab
parentbc21e4d40daeb962699340162547e0fb2b50107f (diff)
merge revision(s) beb85e7eeee4163cd45b69645a60cdb942f72c05: [Backport #21705]
[PATCH] [Bug #21705] Fix segfaults on Windows It should check the type of the argument and coercion before converting the encoding.
-rw-r--r--ext/socket/unixsocket.c3
-rw-r--r--test/socket/test_unix.rb20
-rw-r--r--version.h2
3 files changed, 15 insertions, 10 deletions
diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c
index a8475e3e60..907e54965f 100644
--- a/ext/socket/unixsocket.c
+++ b/ext/socket/unixsocket.c
@@ -43,11 +43,12 @@ unixsock_path_value(VALUE path)
}
}
#endif
+ path = rb_get_path(path);
#ifdef _WIN32
/* UNIXSocket requires UTF-8 per spec. */
path = rb_str_export_to_enc(path, rb_utf8_encoding());
#endif
- return rb_get_path(path);
+ return path;
}
VALUE
diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb
index 3e7d85befc..1a63a75db5 100644
--- a/test/socket/test_unix.rb
+++ b/test/socket/test_unix.rb
@@ -292,14 +292,18 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
File.unlink path if path && File.socket?(path)
end
- def test_open_nul_byte
- tmpfile = Tempfile.new("s")
- path = tmpfile.path
- tmpfile.close(true)
- assert_raise(ArgumentError) {UNIXServer.open(path+"\0")}
- assert_raise(ArgumentError) {UNIXSocket.open(path+"\0")}
- ensure
- File.unlink path if path && File.socket?(path)
+ def test_open_argument
+ assert_raise(TypeError) {UNIXServer.new(nil)}
+ assert_raise(TypeError) {UNIXServer.new(1)}
+ Tempfile.create("s") do |s|
+ path = s.path
+ s.close
+ File.unlink(path)
+ assert_raise(ArgumentError) {UNIXServer.open(path+"\0")}
+ assert_raise(ArgumentError) {UNIXSocket.open(path+"\0")}
+ arg = Struct.new(:to_path).new(path)
+ assert_equal(path, UNIXServer.open(arg) { |server| server.path })
+ end
end
def test_addr
diff --git a/version.h b/version.h
index 9ac6650171..5aa576fd2c 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 10
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 194
+#define RUBY_PATCHLEVEL 195
#include "ruby/version.h"
#include "ruby/internal/abi.h"