From e5c021ceda7e202d70f7121351c314e052483d69 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Fri, 30 Aug 2024 16:11:45 +0900 Subject: [PATCH] out_opentelemetry: Prevent null dereference on memcpy (CID 507910) Signed-off-by: Hiroshi Hatake --- plugins/out_opentelemetry/opentelemetry_utils.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/out_opentelemetry/opentelemetry_utils.c b/plugins/out_opentelemetry/opentelemetry_utils.c index 8c09cfcb4f8..981278ef471 100644 --- a/plugins/out_opentelemetry/opentelemetry_utils.c +++ b/plugins/out_opentelemetry/opentelemetry_utils.c @@ -334,13 +334,15 @@ Opentelemetry__Proto__Common__V1__AnyValue *msgpack_bin_to_otlp_any_value(struct result->bytes_value.len = o->via.bin.size; result->bytes_value.data = flb_malloc(o->via.bin.size); - if (result->bytes_value.data == NULL) { + if (result->bytes_value.data) { + memcpy(result->bytes_value.data, o->via.bin.ptr, o->via.bin.size); + } + else { otlp_any_value_destroy(result); result = NULL; } - memcpy(result->bytes_value.data, o->via.bin.ptr, o->via.bin.size); } return result;