Skip to content

Commit 63d2d29

Browse files
committed
Strip invalid utf8 chars
1 parent 437cc0e commit 63d2d29

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ext/ddtrace.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2777,7 +2777,15 @@ PHP_FUNCTION(DDTrace_add_endpoint) {
27772777
struct ddog_Vec_CharSlice *request_body_type_vec = ddog_CharSlice_to_owned(dd_zend_string_to_CharSlice(request_body_type));
27782778
struct ddog_Vec_CharSlice *response_body_type_vec = ddog_CharSlice_to_owned(dd_zend_string_to_CharSlice(response_body_type));
27792779
struct ddog_Vec_Authentication *authentication_vec = ddog_number_to_owned_Authentication(authentication);
2780-
ddog_CharSlice metadata_slice = dd_zend_string_to_CharSlice(metadata);
2780+
2781+
size_t len = ZSTR_LEN(metadata);
2782+
zend_string *metadata_utf8 = NULL;
2783+
ddog_CharSlice metadata_slice = {0};
2784+
char *stripped_utf8 = ddtrace_strip_invalid_utf8(ZSTR_VAL(metadata), &len);
2785+
if (stripped_utf8 != NULL && len > 0) {
2786+
metadata_utf8 = zend_string_init(stripped_utf8, len, 0);
2787+
metadata_slice = dd_zend_string_to_CharSlice(metadata_utf8);
2788+
}
27812789

27822790
if (!ddtrace_sidecar || !ddtrace_sidecar_instance_id || !DDTRACE_G(sidecar_queue_id)) {
27832791
RETURN_FALSE;

0 commit comments

Comments
 (0)