r1259 - in branches/1.0: . bin/varnishd

des at projects.linpro.no des at projects.linpro.no
Tue Feb 20 09:47:00 CET 2007


Author: des
Date: 2007-02-20 09:47:00 +0100 (Tue, 20 Feb 2007)
New Revision: 1259

Modified:
   branches/1.0/
   branches/1.0/bin/varnishd/varnishd.c
Log:
 r35539 at cat (orig r1239):  phk | 2007-01-29 23:06:33 +0100
 Things you didn't know about C, #7212:
 
 There is no sane way to get sscanf to tell you how many characters 
 were consumed, if you want to allow a variable number of arguments.
  
 The special format %n is patently useless for this, because you 
 have to insert it at every conceiveable point in the string and
 that presumes full explicit whitespace markup.
  
 Parse -w argument "by hand", to catch illegal input like "1,INF,15"
  
 Tripped over by:        Stein Ove Rosseland <steinove at vg.no>
  
 Fixes:  ticket #82
 
 



Property changes on: branches/1.0
___________________________________________________________________
Name: svk:merge
   - d4fa192b-c00b-0410-8231-f00ffab90ce4:/trunk/varnish-cache:1238
   + d4fa192b-c00b-0410-8231-f00ffab90ce4:/trunk/varnish-cache:1239

Modified: branches/1.0/bin/varnishd/varnishd.c
===================================================================
--- branches/1.0/bin/varnishd/varnishd.c	2007-02-20 08:46:59 UTC (rev 1258)
+++ branches/1.0/bin/varnishd/varnishd.c	2007-02-20 08:47:00 UTC (rev 1259)
@@ -32,6 +32,7 @@
  */
 
 #include <err.h>
+#include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
@@ -211,25 +212,47 @@
 static void
 tackle_warg(const char *argv)
 {
-	unsigned int ua, ub, uc;
+	unsigned int u;
+	char *ep, *eq;
 
-	switch (sscanf(argv, "%u,%u,%u", &ua, &ub, &uc)) {
-	case 3:
-		params->wthread_timeout = uc;
-		/* FALLTHROUGH */
-	case 2:
-		if (ub < ua)
-			usage();
-		params->wthread_max = ub;
-		/* FALLTHROUGH */
-	case 1:
-		if (ua < 1)
-			usage();
-		params->wthread_min = ua;
-		break;
-	default:
+	u = strtoul(argv, &ep, 0);
+	if (ep == argv)
 		usage();
+	while (isspace(*ep))
+		ep++;
+	if (u < 1)
+		usage();
+	params->wthread_min = u;
+
+	if (*ep == '\0') {
+		params->wthread_max = params->wthread_min;
+		return;
 	}
+
+	if (*ep != ',')
+		usage();
+	u = strtoul(++ep, &eq, 0);
+	if (eq == ep)
+		usage();
+	if (u < params->wthread_min)
+		usage();
+	while (isspace(*eq))
+		eq++;
+	params->wthread_max = u;
+
+	if (*eq == '\0')
+		return;
+
+	if (*eq != ',')
+		usage();
+	u = strtoul(++eq, &ep, 0);
+	if (ep == eq)
+		usage();
+	while (isspace(*ep))
+		ep++;
+	if (*ep != '\0')
+		usage();
+	params->wthread_timeout = u;
 }
 
 /*--------------------------------------------------------------------




More information about the varnish-commit mailing list