[前][次][番号順一覧][スレッド一覧]

ruby-changes:28100

From: akr <ko1@a...>
Date: Sat, 6 Apr 2013 13:15:07 +0900 (JST)
Subject: [ruby-changes:28100] akr:r40152 (trunk): * ext/socket/socket.c (rsock_sys_fail_path): Use rb_str_inspect only

akr	2013-04-06 13:14:57 +0900 (Sat, 06 Apr 2013)

  New Revision: 40152

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40152

  Log:
    * ext/socket/socket.c (rsock_sys_fail_path): Use rb_str_inspect only
      for String to avoid SEGV.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/socket.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40151)
+++ ChangeLog	(revision 40152)
@@ -1,6 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Apr  6 13:13:39 2013  Tanaka Akira  <akr@f...>
+
+	* 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  <akr@f...>
 
-	* 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.
 
Index: ext/socket/socket.c
===================================================================
--- ext/socket/socket.c	(revision 40151)
+++ ext/socket/socket.c	(revision 40152)
@@ -29,16 +29,21 @@ void https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L29
 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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]