From d0b9aeed0e64cff42ad4f3d87ccd13ace476cd4b Mon Sep 17 00:00:00 2001 From: DavidKorczynski Date: Thu, 19 Oct 2023 17:27:27 +0100 Subject: [PATCH] decode: fix possible NULL dereference (#189) --- src/cmt_decode_msgpack.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmt_decode_msgpack.c b/src/cmt_decode_msgpack.c index 2e1cf31..4ede1bd 100644 --- a/src/cmt_decode_msgpack.c +++ b/src/cmt_decode_msgpack.c @@ -977,8 +977,11 @@ static int unpack_basic_type_meta(mpack_reader_t *reader, size_t index, void *co result = cmt_mpack_unpack_map(reader, callbacks, context); if (CMT_DECODE_MSGPACK_SUCCESS == result) { - decode_context->map->label_count = cfl_list_size(&decode_context->map->label_keys); + if (decode_context->map == NULL || decode_context->map->parent == NULL) { + return CMT_DECODE_MSGPACK_INVALID_ARGUMENT_ERROR; + } + decode_context->map->label_count = cfl_list_size(&decode_context->map->label_keys); if (decode_context->map->type == CMT_HISTOGRAM) { histogram = (struct cmt_histogram *) decode_context->map->parent;