[Vm-dev] [commit][2719] Fix numberic option parsing in sqSocketSetOptions...

commits at squeakvm.org commits at squeakvm.org
Fri Apr 12 19:00:54 UTC 2013


Revision: 2719
Author:   eliot
Date:     2013-04-12 12:00:52 -0700 (Fri, 12 Apr 2013)
Log Message:
-----------
Fix numberic option parsing in sqSocketSetOptions... (quite possibly the longest
C function name I've ever seen).  The old code only supported 1-digit length
values, so setsockopt(SO_SNDBUF, 4096 didn't do what was expected at all
(attempted to set the buffer size to 909717556, which is little-endian ascii
for '4096', '4096' asByteArray unsignedLongAt: 1 => 909717556).

Modified Paths:
--------------
    branches/Cog/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c

Property Changed:
----------------
    branches/Cog/platforms/Cross/vm/sqSCCSVersion.h


Property changes on: branches/Cog/platforms/Cross/vm/sqSCCSVersion.h
___________________________________________________________________
Modified: checkindate
   - Thu Apr 11 16:36:31 PDT 2013
   + Fri Apr 12 11:56:58 PDT 2013

Modified: branches/Cog/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c
===================================================================
--- branches/Cog/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c	2013-04-11 23:37:17 UTC (rev 2718)
+++ branches/Cog/platforms/unix/plugins/SocketPlugin/sqUnixSocket.c	2013-04-12 19:00:52 UTC (rev 2719)
@@ -29,15 +29,17 @@
  * 
  * Support for BSD-style "accept" primitives contributed by:
  *	Lex Spoon <lex at cc.gatech.edu>
+ *
+ * Raw Socket Support by Andreas Raab, RIP.
+ *
+ * Fix to option parsing in sqSocketSetOptions... by Eliot Miranda, 2013/4/12
  * 
  * Notes:
- * 	Sockets are completely asynchronous, but the resolver is still
- *	synchronous.
+ * 	Sockets are completely asynchronous, but the resolver is still synchronous.
  * 
  * BUGS:
  *	Now that the image has real UDP primitives, the TCP/UDP duality in
- *	many of the connection-oriented functions should be removed and
- * 	cremated.
+ *	many of the connection-oriented functions should be removed and cremated.
  */
 
 #include "sq.h"
@@ -1335,14 +1337,13 @@
 
 	  memset((void *)buf, 0, sizeof(buf));
 	  memcpy((void *)buf, optionValue, optionValueSize);
-	  if (optionValueSize == 1)	/* character `1' or `0' */
+	  if (optionValueSize <= sizeof(int)
+	   && (strtol(buf, &endptr, 0),
+	       endptr - buf == optionValueSize)) /* are all option chars digits? */
 	    {
 	      val= strtol(buf, &endptr, 0);
-	      if (endptr != buf)
-		{
 		  memcpy((void *)buf, (void *)&val, sizeof(val));
 		  optionValueSize= sizeof(val);
-		}
 	    }
 	  if ((setsockopt(PSP(s)->s, opt->optlevel, opt->optname,
 			  (const void *)buf, optionValueSize)) < 0)



More information about the Vm-dev mailing list