@@ -408,6 +408,44 @@ void test_hex_to_id()
408408 TEST_CHECK (memcmp (out , expect , sizeof (expect )) == 0 );
409409}
410410
411+ void test_hex_to_id_error_cases ()
412+ {
413+ unsigned char out [16 ];
414+ int ret ;
415+
416+ /* Test zero length string */
417+ ret = flb_otel_utils_hex_to_id ("" , 0 , out , 16 );
418+ TEST_CHECK (ret == 0 ); /* Zero length should succeed (empty output) */
419+
420+ /* Test odd length string */
421+ ret = flb_otel_utils_hex_to_id ("123" , 3 , out , 16 );
422+ TEST_CHECK (ret == -1 ); /* Odd length should fail */
423+
424+ /* Test invalid hex character */
425+ ret = flb_otel_utils_hex_to_id ("0000000000000000000000000000000G" , 32 , out , 16 );
426+ TEST_CHECK (ret == -1 ); /* Invalid hex character should fail */
427+
428+ /* Test mixed valid/invalid hex */
429+ ret = flb_otel_utils_hex_to_id ("0000000000000000000000000000000Z" , 32 , out , 16 );
430+ TEST_CHECK (ret == -1 ); /* Invalid hex character should fail */
431+
432+ /* Test valid hex with wrong output size */
433+ ret = flb_otel_utils_hex_to_id ("00000000000000000000000000000001" , 32 , out , 8 );
434+ TEST_CHECK (ret == 0 ); /* Should succeed even with larger output buffer */
435+
436+ /* Test valid hex with correct size */
437+ ret = flb_otel_utils_hex_to_id ("0000000000000001" , 16 , out , 8 );
438+ TEST_CHECK (ret == 0 ); /* Should succeed */
439+
440+ /* Test valid hex with uppercase */
441+ ret = flb_otel_utils_hex_to_id ("0000000000000000000000000000000A" , 32 , out , 16 );
442+ TEST_CHECK (ret == 0 ); /* Should succeed with uppercase hex */
443+
444+ /* Test valid hex with lowercase */
445+ ret = flb_otel_utils_hex_to_id ("0000000000000000000000000000000a" , 32 , out , 16 );
446+ TEST_CHECK (ret == 0 ); /* Should succeed with lowercase hex */
447+ }
448+
411449void test_convert_string_number_to_u64 ()
412450{
413451 uint64_t val ;
@@ -499,7 +537,7 @@ void test_json_payload_get_wrapped_value()
499537 msgpack_unpacked_destroy (& up );
500538}
501539
502- #define OTEL_TEST_CASES_PATH FLB_TESTS_DATA_PATH "/data/opentelemetry/test_cases .json"
540+ #define OTEL_TEST_CASES_PATH FLB_TESTS_DATA_PATH "/data/opentelemetry/logs .json"
503541#define OTEL_TRACES_TEST_CASES_PATH FLB_TESTS_DATA_PATH "/data/opentelemetry/traces.json"
504542
505543void test_opentelemetry_cases ()
@@ -904,7 +942,6 @@ void test_trace_span_binary_sizes()
904942 struct flb_record_accessor * ra_span_id ;
905943 struct flb_ra_value * val_trace_id ;
906944 struct flb_ra_value * val_span_id ;
907- size_t len ;
908945
909946 /* Test input with trace_id and span_id */
910947 input_json = "{\"resourceLogs\":[{\"scopeLogs\":[{\"logRecords\":[{\"timeUnixNano\":\"1640995200000000000\",\"traceId\":\"5B8EFFF798038103D269B633813FC60C\",\"spanId\":\"EEE19B7EC3C1B174\",\"body\":{\"stringValue\":\"test\"}}]}]}]}" ;
@@ -979,6 +1016,7 @@ void test_trace_span_binary_sizes()
9791016/* Test list */
9801017TEST_LIST = {
9811018 { "hex_to_id" , test_hex_to_id },
1019+ { "hex_to_id_error_cases" , test_hex_to_id_error_cases },
9821020 { "convert_string_number_to_u64" , test_convert_string_number_to_u64 },
9831021 { "find_map_entry_by_key" , test_find_map_entry_by_key },
9841022 { "json_payload_get_wrapped_value" , test_json_payload_get_wrapped_value },
0 commit comments