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

ruby-changes:27190

From: akr <ko1@a...>
Date: Fri, 15 Feb 2013 00:18:01 +0900 (JST)
Subject: [ruby-changes:27190] akr:r39242 (trunk): * ext/socket/sockport.h (VALIDATE_SOCKLEN): new macro to validate

akr	2013-02-15 00:17:49 +0900 (Fri, 15 Feb 2013)

  New Revision: 39242

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

  Log:
    * ext/socket/sockport.h (VALIDATE_SOCKLEN): new macro to validate
      sa_len member of 4.4BSD socket address.
    
    * ext/socket/getnameinfo.c (getnameinfo): use VALIDATE_SOCKLEN,
      instead of SA_LEN.
    
    * ext/socket/socket.c (sock_s_getnameinfo): use VALIDATE_SOCKLEN
      instead of SS_LEN.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/getnameinfo.c
    trunk/ext/socket/socket.c
    trunk/ext/socket/sockport.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39241)
+++ ChangeLog	(revision 39242)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Feb 15 00:15:31 2013  Tanaka Akira  <akr@f...>
+
+	* ext/socket/sockport.h (VALIDATE_SOCKLEN): new macro to validate
+	  sa_len member of 4.4BSD socket address.
+
+	* ext/socket/getnameinfo.c (getnameinfo): use VALIDATE_SOCKLEN,
+	  instead of SA_LEN.
+
+	* ext/socket/socket.c (sock_s_getnameinfo): use VALIDATE_SOCKLEN
+	  instead of SS_LEN. 
+
 Thu Feb 14 22:25:54 2013  Tanaka Akira  <akr@f...>
 
 	* ext/socket/socket.c (sockaddr_len): extracted from sockaddr_obj.
Index: ext/socket/sockport.h
===================================================================
--- ext/socket/sockport.h	(revision 39241)
+++ ext/socket/sockport.h	(revision 39242)
@@ -10,6 +10,12 @@ https://github.com/ruby/ruby/blob/trunk/ext/socket/sockport.h#L10
 #ifndef SOCKPORT_H
 #define SOCKPORT_H
 
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
+# define VALIDATE_SOCKLEN(addr, len) ((addr)->sa_len == (len))
+#else
+# define VALIDATE_SOCKLEN(addr, len) ((void)(addr), (void)(len), 1)
+#endif
+
 #ifdef SA_LEN
 #  define SS_LEN(ss) (ss)->ss_len
 #else
Index: ext/socket/socket.c
===================================================================
--- ext/socket/socket.c	(revision 39241)
+++ ext/socket/socket.c	(revision 39242)
@@ -1235,7 +1235,7 @@ sock_s_getnameinfo(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L1235
 	    rb_raise(rb_eTypeError, "sockaddr length too big");
 	}
 	memcpy(&ss, RSTRING_PTR(sa), RSTRING_LEN(sa));
-	if ((size_t)RSTRING_LEN(sa) != SS_LEN(&ss)) {
+        if (!VALIDATE_SOCKLEN((struct sockaddr *)&ss, RSTRING_LEN(sa))) {
 	    rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
 	}
 	sap = (struct sockaddr*)&ss;
Index: ext/socket/getnameinfo.c
===================================================================
--- ext/socket/getnameinfo.c	(revision 39241)
+++ ext/socket/getnameinfo.c	(revision 39242)
@@ -151,8 +151,8 @@ getnameinfo(const struct sockaddr *sa, s https://github.com/ruby/ruby/blob/trunk/ext/socket/getnameinfo.c#L151
 	if (sa == NULL)
 		return ENI_NOSOCKET;
 
-	len = SA_LEN(sa);
-	if (len != salen) return ENI_SALEN;
+	if (!VALIDATE_SOCKLEN(sa, salen)) return ENI_SALEN;
+        len = salen;
 
 	family = sa->sa_family;
 	for (i = 0; afdl[i].a_af; i++)

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

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