Remove inappropriate jsonp_free which caused segmentation fault.

pack_string should never free str on error.  This wouldn't be a problem
except the check for `ours` was inverted.  Just remove the check for
ours since the true condition is unreachable.

json_vpack_ex also had an error check for s.has_error.  This can never
be true unless value is NULL.

Expand pack_unpack testing to cover empty format string, NULL object
value with non-null concatenated key, array containing a non-null object
after a NULL (error) string.

Fixes #444
This commit is contained in:
Corey Farrell
2018-11-05 16:43:10 -05:00
parent 6ac0eefed0
commit e262ea5fcd
2 changed files with 23 additions and 7 deletions

View File

@@ -359,9 +359,7 @@ static json_t *pack_string(scanner_t *s, va_list *ap)
return t == '?' && !s->has_error ? json_null() : NULL;
if (s->has_error) {
if (!ours)
jsonp_free(str);
/* It's impossible to reach this point if ours != 0, do not free str. */
return NULL;
}
@@ -853,6 +851,7 @@ json_t *json_vpack_ex(json_error_t *error, size_t flags,
value = pack(&s, &ap_copy);
va_end(ap_copy);
/* This will cover all situations where s.has_error is true */
if(!value)
return NULL;
@@ -862,10 +861,6 @@ json_t *json_vpack_ex(json_error_t *error, size_t flags,
set_error(&s, "<format>", json_error_invalid_format, "Garbage after format string");
return NULL;
}
if(s.has_error) {
json_decref(value);
return NULL;
}
return value;
}