diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/socket/unixsocket.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c index 5a44b552f8..75f17d6c10 100644 --- a/ext/socket/unixsocket.c +++ b/ext/socket/unixsocket.c @@ -25,6 +25,28 @@ unixsock_connect_internal(VALUE a) arg->sockaddrlen, 0); } +static VALUE +unixsock_path_value(VALUE path) +{ +#ifdef __linux__ +#define TO_STR_FOR_LINUX_ABSTRACT_NAMESPACE 0 + + VALUE name = path; +#if TO_STR_FOR_LINUX_ABSTRACT_NAMESPACE + const int isstr = !NIL_P(name = rb_check_string_type(name)); +#else + const int isstr = RB_TYPE_P(name, T_STRING); +#endif + if (isstr) { + if (RSTRING_LEN(name) == 0 || RSTRING_PTR(name)[0] == '\0') { + rb_check_safe_obj(name); + return name; /* ignore encoding */ + } + } +#endif + return rb_get_path(path); +} + VALUE rsock_init_unixsock(VALUE sock, VALUE path, int server) { @@ -33,7 +55,7 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server) int fd, status; rb_io_t *fptr; - SafeStringValue(path); + path = unixsock_path_value(path); INIT_SOCKADDR_UN(&sockaddr, sizeof(struct sockaddr_un)); if (sizeof(sockaddr.sun_path) < (size_t)RSTRING_LEN(path)) { |