]> granicus.if.org Git - file/commitdiff
simplify numeric parsing (found by oss-fuzz)
authorChristos Zoulas <christos@zoulas.com>
Mon, 20 Aug 2018 08:06:54 +0000 (08:06 +0000)
committerChristos Zoulas <christos@zoulas.com>
Mon, 20 Aug 2018 08:06:54 +0000 (08:06 +0000)
src/is_json.c

index 527b26c44bf516352d672ae51b4428a36372a6b1..61bdc4df8afb67154eaa9e32ffcbb82573377230 100644 (file)
@@ -32,7 +32,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: is_json.c,v 1.7 2018/08/17 09:12:33 christos Exp $")
+FILE_RCSID("@(#)$File: is_json.c,v 1.8 2018/08/20 08:06:54 christos Exp $")
 #endif
 
 #include <string.h>
@@ -261,6 +261,8 @@ json_parse_number(const unsigned char **ucp, const unsigned char *ue)
                        break;
                got = 1;
        }
+       if (uc == ue)
+               goto out;
        if (*uc == '.')
                uc++;
        for (; uc < ue; uc++) {
@@ -268,9 +270,13 @@ json_parse_number(const unsigned char **ucp, const unsigned char *ue)
                        break;
                got = 1;
        }
+       if (uc == ue)
+               goto out;
        if (got && (*uc == 'e' || *uc == 'E')) {
                uc++;
                got = 0;
+               if (uc == ue)
+                       goto out;
                if (*uc == '+' || *uc == '-')
                        uc++;
                for (; uc < ue; uc++) {
@@ -279,13 +285,13 @@ json_parse_number(const unsigned char **ucp, const unsigned char *ue)
                        got = 1;
                }
        }
-       ue = *ucp;
-       if (!got || uc == ue)
+out:
+       if (!got)
                DPRINTF("Bad number: ", uc, *ucp);
        else
                DPRINTF("Good number: ", uc, *ucp);
        *ucp = uc;
-       return uc != ue && got;
+       return got;
 }
                
 static int