diff options
author | Janeks Jaunups <th3n3x@gmail.com> | 2014-05-06 07:30:15 +0200 |
---|---|---|
committer | Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> | 2014-05-06 07:30:15 +0200 |
commit | 12452d6a15fdc50ce53a1fe428fd2520979d7aa6 (patch) | |
tree | 34cb2fffbf452263587d73aebcdec2ebfaa6c5ac /lib | |
parent | cf5e55f3bab6696e72dfb59bf31064678e391891 (diff) |
ipset: Handle missing leading zeros in ethernet address parser
ipset would not parse ether addresses which are not exactly
17 characters long, for ex. 1:2:3:4:5:6, which is fixed in
the patch.
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/parse.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/parse.c b/lib/parse.c index 4db872e..be6e833 100644 --- a/lib/parse.c +++ b/lib/parse.c @@ -180,24 +180,27 @@ int ipset_parse_ether(struct ipset_session *session, enum ipset_opt opt, const char *str) { - unsigned int i = 0; + size_t len, p = 0, i = 0; unsigned char ether[ETH_ALEN]; assert(session); assert(opt == IPSET_OPT_ETHER); assert(str); - if (strlen(str) != ETH_ALEN * 3 - 1) + len = strlen(str); + + if (len > ETH_ALEN * 3 - 1) goto error; for (i = 0; i < ETH_ALEN; i++) { long number; char *end; - number = strtol(str + i * 3, &end, 16); + number = strtol(str + p, &end, 16); + p = end - str + 1; - if (end == str + i * 3 + 2 && - (*end == ':' || *end == '\0') && + if (((*end == ':' && i < ETH_ALEN - 1) || + (*end == '\0' && i == ETH_ALEN - 1)) && number >= 0 && number <= 255) ether[i] = number; else |