diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-07-11 11:15:06 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-07-11 15:10:33 +0200 |
commit | 2eb1c19881678851a7e514a9d024fac248b309d1 (patch) | |
tree | a7a4ecde504e3a1117be03adb51c33609ecd8475 /src/shared/json.c | |
parent | Merge pull request #13018 from yuwata/network-tunnel-follow-up-13016 (diff) | |
download | systemd-2eb1c19881678851a7e514a9d024fac248b309d1.tar.xz systemd-2eb1c19881678851a7e514a9d024fac248b309d1.zip |
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
Diffstat (limited to '')
-rw-r--r-- | src/shared/json.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/shared/json.c b/src/shared/json.c index a068049b57..f1bb50cfa2 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; |