Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(profiling) invalid unicode handling in timeline #2988

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions profiling/src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@ extern "C" {
#[cfg(php7)]
pub fn zend_register_extension(extension: &ZendExtension, handle: *mut c_void) -> ZendResult;

/// Converts the `const char *` into a `zai_str`. A None as well as empty
/// strings will be converted into a string view to a static empty string
/// (single byte of null, len of 0).
pub fn zai_str_from_cstr(cstr: *const c_char) -> zai_str<'static>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The <'static> lifetime might be a lie 😞


/// Converts the `zstr` into a `zai_str`. A None as well as empty
/// strings will be converted into a string view to a static empty string
/// (single byte of null, len of 0).
Expand Down
9 changes: 1 addition & 8 deletions profiling/src/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,7 @@ unsafe extern "C" fn ddog_php_prof_zend_error_observer(
}

#[cfg(zend_error_observer_80)]
let file = unsafe {
let mut len = 0;
let file = file as *const u8;
while *file.add(len) != 0 {
len += 1;
}
std::str::from_utf8_unchecked(std::slice::from_raw_parts(file, len)).to_string()
};
let file = unsafe { zend::zai_str_from_cstr(file).into_string() };
#[cfg(not(zend_error_observer_80))]
let file = unsafe { zend::zai_str_from_zstr(file.as_mut()).into_string() };

Expand Down
2 changes: 2 additions & 0 deletions zend_abstract_interface/zai_string/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

char *ZAI_STRING_EMPTY_PTR = "";

extern inline zai_str zai_str_from_cstr(const char *cstr);

extern inline zai_str zai_str_from_zstr(zend_string *zstr);

extern inline zai_string zai_string_concat3(zai_str first, zai_str second, zai_str third);
2 changes: 1 addition & 1 deletion zend_abstract_interface/zai_string/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static inline zai_str zai_str_new(const char *ptr, size_t len) {
*
* If the pointer is known to be non-null, use ZAI_STR_FROM_CSTR directly.
*/
static inline zai_str zai_str_from_cstr(const char *cstr) {
inline zai_str zai_str_from_cstr(const char *cstr) {
if (cstr) {
return (zai_str)ZAI_STR_FROM_CSTR(cstr);
}
Expand Down
Loading