From: Lennart Poettering Date: Thu, 11 Jul 2019 09:15:06 +0000 (+0200) Subject: json: always allocate at least sizeof(JsonVariant) bytes X-Git-Tag: v243-rc1~154 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2eb1c19881678851a7e514a9d024fac248b309d1;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/shared/json.c b/src/shared/json.c index a068049b57f..f1bb50cfa2c 100644 --- a/src/shared/json.c +++ b/src/shared/json.c @@ -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;