X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fnaddress.c;h=fb6fdfe9c6212480f60d0204402f6962237c3369;hb=859c1061d8e71309382f147a2497b272bf0abb9b;hp=349e2d7af8477d72e2a14435204e2dd5b358e128;hpb=820076e1d48f75a6cdcb65e2a97a19f42e2c2734;p=util-vserver.git diff --git a/src/naddress.c b/src/naddress.c index 349e2d7..fb6fdfe 100644 --- a/src/naddress.c +++ b/src/naddress.c @@ -244,7 +244,7 @@ parseIPFormat(char const *str_c, struct vc_ips **ips, size_t len = strlen(str_c); char const *fc; char str[len + 1], *ptr = str; - int ret = -1; + int ret = 0; strcpy(str, str_c); @@ -261,9 +261,10 @@ parseIPFormat(char const *str_c, struct vc_ips **ips, default: goto out; } - if ((sep = memchr(ptr, *(fc + 1), len)) == NULL) { + if (len == 0) goto out; - } + if ((sep = memchr(ptr, *(fc + 1), len)) == NULL) + sep = ptr + len; *sep = '\0'; /* This is ugly, and means that m cannot be first */ @@ -280,6 +281,7 @@ parseIPFormat(char const *str_c, struct vc_ips **ips, unsigned long sz; if (!isNumberUnsigned(ptr, &sz, true) || sz > limit) { + ret = -1; goto out; } @@ -295,6 +297,7 @@ parseIPFormat(char const *str_c, struct vc_ips **ips, } else { if (convertAddress(ptr, &(*ips)->a.vna_type, dst) == -1) { + ret = -1; goto out; } else if (*fc == 'm') { @@ -303,15 +306,15 @@ parseIPFormat(char const *str_c, struct vc_ips **ips, } } + ret++; + len -= (sep - ptr); ptr = sep + 1; if (*(fc + 1) == '\0') break; } - ret = 0; out: - free(str); return ret; } @@ -319,7 +322,7 @@ static void readIP(char const *str, struct vc_ips **ips, uint16_t type) { if (ifconfig_getaddr(str, &(*ips)->a.vna_v4_ip.s_addr, &(*ips)->a.vna_v4_mask.s_addr, NULL)==-1) { - if (parseIPFormat(str, ips, "1/m") == -1) { + if (parseIPFormat(str, ips, "1/m") < 1) { WRITE_MSG(2, "Invalid IP number '"); WRITE_STR(2, str); WRITE_MSG(2, "'\n"); @@ -355,7 +358,7 @@ readBcast(char const *str, struct vc_ips **ips) static void readRange(char const *str, struct vc_ips **ips) { - if (parseIPFormat(str, ips, "1-2/m") == -1) { + if (parseIPFormat(str, ips, "1-2/m") < 2) { WRITE_MSG(2, "Invalid range '"); WRITE_STR(2, str); WRITE_MSG(2, "'\n");