Hi Wensong,
This patch addresses following things:
o use stdc numbers for UINT{8,16,32}_MAX
o change int to unsigned int as no caller uses negative values
o fix {l,u}_threshold to allow uint32_t
o fix missing check for l_theshold > u_threshold
Please consider applying ... actually, just do it :).
Best regards,
Roberto Nibali, ratz
--
echo '[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq'|dc
--- ipvs-1.1.6/ipvs/ipvsadm/ipvsadm.c 2003-06-08 11:31:36.000000000 +0200
+++ ipvs-1.1.6-ratz/ipvs/ipvsadm/ipvsadm.c 2003-07-24 22:24:31.000000000
+0200
@@ -267,7 +267,7 @@
/* various parsing helpers & parsing functions */
static int str_is_digit(const char *str);
-static int string_to_number(const char *s, int min, int max);
+static int string_to_number(const char *s, unsigned int min, unsigned int max);
static int host_to_addr(const char *name, struct in_addr *addr);
static char * addr_to_host(struct in_addr *addr);
static char * addr_to_anyname(struct in_addr *addr);
@@ -531,20 +531,23 @@
case 'w':
set_option(options, OPT_WEIGHT);
if ((ce->dest.weight =
- string_to_number(optarg, 0, 65535)) == -1)
+ string_to_number(optarg, 0, UINT16_MAX)) == -1)
fail(2, "illegal weight specified");
break;
case 'x':
set_option(options, OPT_UTHRESHOLD);
if ((ce->dest.u_threshold =
- string_to_number(optarg, 0, 65535)) == -1)
+ string_to_number(optarg, 0, UINT32_MAX)) == -1)
fail(2, "illegal u_threshold specified");
break;
case 'y':
set_option(options, OPT_LTHRESHOLD);
if ((ce->dest.l_threshold =
- string_to_number(optarg, 0, 65535)) == -1)
+ string_to_number(optarg, 0, UINT32_MAX)) == -1)
fail(2, "illegal l_threshold specified");
+ if (ce->dest.l_threshold > ce->dest.u_threshold) {
+ fail(2, "l_threshold must be lower than
u_threshold");
+ }
break;
case 'c':
set_option(options, OPT_CONNECTION);
@@ -561,7 +564,7 @@
case 'I':
set_option(options, OPT_SYNCID);
if ((ce->daemon.syncid =
- string_to_number(optarg, 0, 255)) == -1)
+ string_to_number(optarg, 0, UINT8_MAX)) == -1)
fail(2, "illegal syncid specified");
break;
case '5':
@@ -843,20 +846,23 @@
case 'w':
set_option(options, OPT_WEIGHT);
if ((ce->dest.weight =
- string_to_number(optarg, 0, 65535)) == -1)
+ string_to_number(optarg, 0, UINT16_MAX)) == -1)
fail(2, "illegal weight specified");
break;
case 'x':
set_option(options, OPT_UTHRESHOLD);
if ((ce->dest.u_threshold =
- string_to_number(optarg, 0, 65535)) == -1)
+ string_to_number(optarg, 0, UINT32_MAX)) == -1)
fail(2, "illegal u_threshold specified");
break;
case 'y':
set_option(options, OPT_LTHRESHOLD);
if ((ce->dest.l_threshold =
- string_to_number(optarg, 0, 65535)) == -1)
+ string_to_number(optarg, 0, UINT32_MAX)) == -1)
fail(2, "illegal l_threshold specified");
+ if (ce->dest.l_threshold > ce->dest.u_threshold) {
+ fail(2, "l_threshold must be lower than
u_threshold");
+ }
break;
case 'c':
set_option(options, OPT_CONNECTION);
@@ -873,7 +879,7 @@
case 'I':
set_option(options, OPT_SYNCID);
if ((ce->daemon.syncid =
- string_to_number(optarg, 0, 255)) == -1)
+ string_to_number(optarg, 0, UINT8_MAX)) == -1)
fail(2, "illegal syncid specified");
break;
case '5':
@@ -1064,13 +1070,13 @@
}
-static int string_to_number(const char *s, int min, int max)
+static int string_to_number(const char *s, unsigned int min, unsigned int max)
{
- long number;
+ unsigned long number;
char *end;
errno = 0;
- number = strtol(s, &end, 10);
+ number = strtoul(s, &end, 10);
if (*end == '\0' && end != s) {
/* We parsed a number, let's see if we want this. */
if (errno != ERANGE && min <= number && number <= max)
@@ -1173,7 +1179,7 @@
if (portp != NULL){
result |= SERVICE_PORT;
- if ((portn=string_to_number(portp+1, 0, 65535)) != -1)
+ if ((portn=string_to_number(portp+1, 0, UINT16_MAX)) != -1)
*port = htons(portn);
else if ((portn=service_to_port(portp+1, proto)) != -1)
*port = htons(portn);
|