summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-28 15:42:09 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-28 15:42:09 +0000
commiteb9f446ebf64dde94f69daa5cdbc2d84ce68eb4d (patch)
treef19b6b36f83c848b1facfb153fb7cf5460794c02 /ext
parentb73eaef7a802b0fdbaa5b700e79e6fe477b67efa (diff)
* ext/socket/unixsocket.c (rsock_init_unixsock): Open a socket
after path length check. This fixes a fd leak by TestSocket_UNIXSocket#test_too_long_path. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/unixsocket.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c
index 519343b558e..0a1b65a5b96 100644
--- a/ext/socket/unixsocket.c
+++ b/ext/socket/unixsocket.c
@@ -34,10 +34,6 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
rb_io_t *fptr;
SafeStringValue(path);
- fd = rsock_socket(AF_UNIX, SOCK_STREAM, 0);
- if (fd < 0) {
- rsock_sys_fail_path("socket(2)", path);
- }
INIT_SOCKADDR_UN(&sockaddr, sizeof(struct sockaddr_un));
if (sizeof(sockaddr.sun_path) < (size_t)RSTRING_LEN(path)) {
@@ -47,6 +43,11 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
sockaddrlen = rsock_unix_sockaddr_len(path);
+ fd = rsock_socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
+ rsock_sys_fail_path("socket(2)", path);
+ }
+
if (server) {
status = bind(fd, (struct sockaddr*)&sockaddr, sockaddrlen);
}