[PATCH][BZ #15277] Fix inet_network("1 bar")
Ondřej Bílka
neleai@seznam.cz
Thu Oct 17 15:39:00 GMT 2013
On Tue, Oct 08, 2013 at 09:13:31PM +0200, OndÅej BÃlka wrote:
> Hi,
>
> Here we do not detect that address is invalid as code only checked if
> first byte after address is space. This patch checks rest of string for
> nonspace characters.
>
> Author of this bug added several cases to testcase, should we include
> them or just 1 bar one.
>
> https://sourceware.org/bugzilla/show_bug.cgi?id=15277
>
Here is version that adds one test. OK to commit?
[BZ #15277]
* inet/inet_net.c (inet_network): Properly detect invalid strings.
* inet/tst-network.c: Add testcase.
diff --git a/inet/inet_net.c b/inet/inet_net.c
index 68e232f..85ce6b3 100644
--- a/inet/inet_net.c
+++ b/inet/inet_net.c
@@ -81,7 +81,9 @@ again:
*pp++ = val, cp++;
goto again;
}
- if (*cp && !isspace(*cp))
+ while (isspace(*cp))
+ cp++;
+ if (*cp)
return (INADDR_NONE);
if (pp >= parts + 4 || val > 0xff)
return (INADDR_NONE);
diff --git a/inet/tst-network.c b/inet/tst-network.c
index 6b79e62..ae3f938 100644
--- a/inet/tst-network.c
+++ b/inet/tst-network.c
@@ -38,6 +38,7 @@ struct
{"0x0", 0},
/* Now some invalid addresses. */
{"0x", INADDR_NONE},
+ {"1 bar", INADDR_NONE},
{"141.30.225.2800", INADDR_NONE},
{"141.76.1.1.1", INADDR_NONE},
{"141.76.1.11.", INADDR_NONE},
More information about the Libc-alpha
mailing list