From 9c48a48a23398d2f16309ecbc5b595e27c6c9a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Szcz=C4=99k?= Date: Wed, 5 Jun 2024 11:21:23 +0200 Subject: [PATCH] json: use secure un{base64,hex}mem for sensitive variants While tracing a LUKS code path in homework, I've noticed that we don't erase buffers when doing unbase64 or unhex on JSON variants, even if the variant is marked as sensitive. (cherry picked from commit 80313c55770ef0e2174fe5750680e426278416cb) (cherry picked from commit cce7df4079c2ac48c6a6be85785332c6764522b9) (cherry picked from commit 2dee0040d0c555fbca4312da8ad2378a18757322) (cherry picked from commit d5a7b54895756b6ed706a7266ce76c66d2d1d3f4) --- src/shared/json.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/json.c b/src/shared/json.c index e39c1044943..ac89b81de83 100644 --- a/src/shared/json.c +++ b/src/shared/json.c @@ -4772,14 +4772,14 @@ int json_variant_unbase64(JsonVariant *v, void **ret, size_t *ret_size) { if (!json_variant_is_string(v)) return -EINVAL; - return unbase64mem(json_variant_string(v), SIZE_MAX, ret, ret_size); + return unbase64mem_full(json_variant_string(v), SIZE_MAX, /* secure= */ json_variant_is_sensitive(v), ret, ret_size); } int json_variant_unhex(JsonVariant *v, void **ret, size_t *ret_size) { if (!json_variant_is_string(v)) return -EINVAL; - return unhexmem(json_variant_string(v), SIZE_MAX, ret, ret_size); + return unhexmem_full(json_variant_string(v), SIZE_MAX, /* secure= */ json_variant_is_sensitive(v), ret, ret_size); } static const char* const json_variant_type_table[_JSON_VARIANT_TYPE_MAX] = {