Skip to content

Commit c576b1e

Browse files
committed
opentelemetry: logs: strict check when decoding IDs
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 1a98519 commit c576b1e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/opentelemetry/flb_opentelemetry_logs.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,24 @@ static int process_json_payload_log_records_entry(
302302
}
303303

304304
if (trace_id != NULL && trace_id->type == MSGPACK_OBJECT_STR && trace_id->via.str.size == 32) {
305-
flb_otel_utils_hex_to_id(trace_id->via.str.ptr, trace_id->via.str.size, tmp_id, 16);
305+
if (flb_otel_utils_hex_to_id(trace_id->via.str.ptr, trace_id->via.str.size, tmp_id, 16) != 0) {
306+
if (error_status) {
307+
*error_status = FLB_OTEL_LOGS_ERR_INVALID_TRACE_ID;
308+
}
309+
return -FLB_OTEL_LOGS_ERR_INVALID_TRACE_ID;
310+
}
306311
flb_log_event_encoder_append_metadata_values(encoder,
307312
FLB_LOG_EVENT_STRING_VALUE("trace_id", 8),
308313
FLB_LOG_EVENT_BINARY_VALUE(tmp_id, 16));
309314
}
310315

311316
if (span_id != NULL && span_id->type == MSGPACK_OBJECT_STR && span_id->via.str.size == 16) {
312-
flb_otel_utils_hex_to_id(span_id->via.str.ptr, span_id->via.str.size, tmp_id, 8);
317+
if (flb_otel_utils_hex_to_id(span_id->via.str.ptr, span_id->via.str.size, tmp_id, 8) != 0) {
318+
if (error_status) {
319+
*error_status = FLB_OTEL_LOGS_ERR_INVALID_SPAN_ID;
320+
}
321+
return -FLB_OTEL_LOGS_ERR_INVALID_SPAN_ID;
322+
}
313323
flb_log_event_encoder_append_metadata_values(encoder,
314324
FLB_LOG_EVENT_STRING_VALUE("span_id", 7),
315325
FLB_LOG_EVENT_BINARY_VALUE(tmp_id, 8));

0 commit comments

Comments
 (0)