Commit 3dbaf9e1 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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@vg.no>
 
Fixes:  ticket #82



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1239 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 7e977924
......@@ -32,6 +32,7 @@
*/
#include <err.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
......@@ -211,25 +212,47 @@ usage(void)
static void
tackle_warg(const char *argv)
{
unsigned int ua, ub, uc;
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:
unsigned int u;
char *ep, *eq;
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;
}
/*--------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment