diff --git a/ChangeLog b/ChangeLog index 73dde98274..32ca122a45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ +Sat Apr 6 13:13:39 2013 Tanaka Akira + + * ext/socket/socket.c (rsock_sys_fail_path): Use rb_str_inspect only + for String to avoid SEGV. + Sat Apr 6 12:40:16 2013 Tanaka Akira - * ext/socket/rubysocket.h (rsock_sys_fail_host_port) Wrap by NORETURN. + * ext/socket/rubysocket.h (rsock_sys_fail_host_port): Wrap by NORETURN. (rsock_sys_fail_path): Ditto. (rsock_sys_fail_sockaddr): Ditto. diff --git a/ext/socket/socket.c b/ext/socket/socket.c index be7bd62236..3ee725d8b5 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -29,16 +29,21 @@ void rsock_sys_fail_path(const char *mesg, VALUE path) { VALUE message; - if (memchr(RSTRING_PTR(path), '\0', RSTRING_LEN(path))) { - path = rb_str_inspect(path); - message = rb_sprintf("%s for %s", mesg, - StringValueCStr(path)); + if (RB_TYPE_P(path, T_STRING)) { + if (memchr(RSTRING_PTR(path), '\0', RSTRING_LEN(path))) { + path = rb_str_inspect(path); + message = rb_sprintf("%s for %s", mesg, + StringValueCStr(path)); + } + else { + message = rb_sprintf("%s for \"%s\"", mesg, + StringValueCStr(path)); + } + rb_sys_fail_str(message); } else { - message = rb_sprintf("%s for \"%s\"", mesg, - StringValueCStr(path)); + rb_sys_fail(mesg); } - rb_sys_fail_str(message); } void