Spotted by Coverity Scan

Signed-off-by: Fabio M. Di Nitto <fdini...@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

Reply via email to