diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2012-05-10 00:59:30 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2012-05-10 00:59:30 -0400 |
commit | 89c65c4dc2132a36e4f0c8ac534cb2454803bf41 (patch) | |
tree | d03019ed8d3d2799ce6f00789d852f71b9c85ecc /json.c | |
parent | 9d7dc31b595b91aeb258faca459909b0b5b7965e (diff) | |
download | gpsd-89c65c4dc2132a36e4f0c8ac534cb2454803bf41.tar.gz |
Armor the JSON code against zeroed value or attribute pointers.
Should never happen, but having the bailout logic in plavce creates static
invariants that should banish a bunch of Coverity warnings.
Diffstat (limited to 'json.c')
-rw-r--r-- | json.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -259,6 +259,8 @@ static int json_internal_read_object(const char *cp, } break; case in_attr: + if (pattr == NULL) + return JSON_ERR_NULLPTR; if (*cp == '"') { *pattr++ = '\0'; json_debug_trace((1, "Collected attribute name %s\n", @@ -320,6 +322,8 @@ static int json_internal_read_object(const char *cp, } break; case in_val_string: + if (pval == NULL) + return JSON_ERR_NULLPTR; if (*cp == '\\') state = in_escape; else if (*cp == '"') { @@ -334,6 +338,8 @@ static int json_internal_read_object(const char *cp, *pval++ = *cp; break; case in_escape: + if (pval == NULL) + return JSON_ERR_NULLPTR; switch (*cp) { case 'b': *pval++ = '\b'; @@ -364,6 +370,8 @@ static int json_internal_read_object(const char *cp, state = in_val_string; break; case in_val_token: + if (pval == NULL) + return JSON_ERR_NULLPTR; if (isspace(*cp) || *cp == ',' || *cp == '}') { *pval = '\0'; json_debug_trace((1, "Collected token value %s.\n", valbuf)); @@ -635,6 +643,7 @@ const /*@observer@*/ char *json_error_string(int err) "saw quoted value when expecting nonstring", "didn't see quoted value when expecting string", "other data conversion error", + "unexpected null value or attribute pointer", }; if (err <= 0 || err >= (int)(sizeof(errors) / sizeof(errors[0]))) |