From: Justin Mayfield Date: Thu, 10 May 2012 03:08:30 +0000 (-0600) Subject: __str2flags fix X-Git-Tag: libnl3_2_10~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=32057bc15469e6f012841605daa38766497fa196;p=thirdparty%2Flibnl.git __str2flags fix I found a minor bug in __str2flags where empty strings or short strings will match all or many flags respectively. Basically the test needs to ensure the test string is the same length as the table entry before doing a strncasecmp to avoid doing just a prefix test. --- diff --git a/lib/utils.c b/lib/utils.c index 0ec7626..83d424f 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -993,7 +993,8 @@ int __str2flags(const char *buf, const struct trans_tbl *tbl, size_t tbl_len) t = strchr(p, ','); len = t ? t - p : strlen(p); for (i = 0; i < tbl_len; i++) - if (!strncasecmp(tbl[i].a, p, len)) + if (len == strlen(tbl[i].a) && + !strncasecmp(tbl[i].a, p, len)) flags |= tbl[i].i; if (!t)