[Cluster-devel] [PATCH 08/19] config: improve string error checking in tokenizer
Fabio M. Di Nitto
fdinitto at redhat.com
Tue Oct 25 12:08:59 UTC 2011
Spotted by Coverity Scan
Signed-off-by: Fabio M. Di Nitto <fdinitto at redhat.com>
---
:100644 100644 0a21f85... 710c176... M config/libs/libccsconfdb/xpathlite.c
config/libs/libccsconfdb/xpathlite.c | 20 +++++++++++++++-----
1 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/config/libs/libccsconfdb/xpathlite.c b/config/libs/libccsconfdb/xpathlite.c
index 0a21f85..710c176 100644
--- a/config/libs/libccsconfdb/xpathlite.c
+++ b/config/libs/libccsconfdb/xpathlite.c
@@ -15,13 +15,18 @@ static int tokenizer(char *current_query)
int tokens = 0;
char *curpos = current_query;
char *next = NULL;
- char *end;
+ char *end = NULL;
end = current_query + strlen(current_query);
while (curpos <= end) {
tokens++;
+ if (!curpos) {
+ errno = EINVAL;
+ return -1;
+ }
+
if (strncmp(curpos, "/", 1)) {
errno = EINVAL;
return -1;
@@ -39,11 +44,16 @@ static int tokenizer(char *current_query)
if (!next)
return tokens;
- if ((strstr(curpos, "[") > next) || !strstr(curpos, "["))
+ if ((strstr(curpos, "[") > next) || !strstr(curpos, "[")) {
curpos = next;
- else
- curpos = strstr(strstr(curpos, "]"), "/");
-
+ } else {
+ curpos = strstr(curpos, "]");
+ if (!curpos) {
+ errno = EINVAL;
+ return -1;
+ }
+ curpos = strstr(curpos, "/");
+ }
}
errno = EINVAL;
return -1;
--
1.7.4.4
More information about the Cluster-devel
mailing list