json: always allocate at least sizeof(JsonVariant) bytes

ubsan apparently doesn't like us being too smart here. Given the
difference is just a few bytes, let's avoid the noise.

Fixes: #13020
This commit is contained in:
Lennart Poettering 2019-07-11 11:15:06 +02:00
parent 66d3159739
commit 2eb1c19881
1 changed files with 6 additions and 3 deletions

View File

@ -279,7 +279,8 @@ static int json_variant_new(JsonVariant **ret, JsonVariantType type, size_t spac
assert_return(ret, -EINVAL);
v = malloc0(offsetof(JsonVariant, value) + space);
v = malloc0(MAX(sizeof(JsonVariant),
offsetof(JsonVariant, value) + space));
if (!v)
return -ENOMEM;
@ -1664,7 +1665,8 @@ static int json_variant_copy(JsonVariant **nv, JsonVariant *v) {
default:
/* Everything else copy by reference */
c = malloc0(offsetof(JsonVariant, reference) + sizeof(JsonVariant*));
c = malloc0(MAX(sizeof(JsonVariant),
offsetof(JsonVariant, reference) + sizeof(JsonVariant*)));
if (!c)
return -ENOMEM;
@ -1677,7 +1679,8 @@ static int json_variant_copy(JsonVariant **nv, JsonVariant *v) {
return 0;
}
c = malloc0(offsetof(JsonVariant, value) + k);
c = malloc0(MAX(sizeof(JsonVariant),
offsetof(JsonVariant, value) + k));
if (!c)
return -ENOMEM;