From 6f5ba31553a22f4db68ec8655fcf1a8147966f4f Mon Sep 17 00:00:00 2001 From: minhdiep Date: Thu, 18 Nov 2010 15:04:54 -0700 Subject: [PATCH] b=24170 checking len of debug string before matching i=vitaly i=rahul We need to check the len before matching the string to prevent something like net matches neterror --- libcfs/libcfs/libcfs_string.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libcfs/libcfs/libcfs_string.c b/libcfs/libcfs/libcfs_string.c index 2f76682..83ad82b 100644 --- a/libcfs/libcfs/libcfs_string.c +++ b/libcfs/libcfs/libcfs_string.c @@ -69,6 +69,7 @@ static int cfs_strncasecmp(const char *s1, const char *s2, size_t n) int cfs_str2mask(const char *str, const char *(*bit2str)(int bit), int *oldmask, int minmask, int allmask) { + const char *debugstr; char op = 0; int newmask = minmask, i, len, found = 0; ENTRY; @@ -101,7 +102,10 @@ int cfs_str2mask(const char *str, const char *(*bit2str)(int bit), /* match token */ found = 0; for (i = 0; i < 32; i++) { - if (cfs_strncasecmp(str, bit2str(i), len) == 0) { + debugstr = bit2str(i); + if (debugstr != NULL && + strlen(debugstr) == len && + cfs_strncasecmp(str, debugstr, len) == 0) { if (op == '-') newmask &= ~(1 << i); else @@ -110,7 +114,8 @@ int cfs_str2mask(const char *str, const char *(*bit2str)(int bit), break; } } - if (!found && (cfs_strncasecmp(str, "ALL", len) == 0)) { + if (!found && len == 3 && + (cfs_strncasecmp(str, "ALL", len) == 0)) { if (op == '-') newmask = minmask; else -- 1.8.3.1