Skip to content

Intercept strlcpy and strlcat for msan on Clang 17 #12674

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

Merged
merged 1 commit into from
Nov 15, 2023
Merged
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
28 changes: 28 additions & 0 deletions Zend/zend_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
# include "valgrind/callgrind.h"
#endif

#if __has_feature(memory_sanitizer)
# include <sanitizer/msan_interface.h>
#endif

ZEND_API zend_new_interned_string_func_t zend_new_interned_string;
ZEND_API zend_string_init_interned_func_t zend_string_init_interned;
ZEND_API zend_string_init_existing_interned_func_t zend_string_init_existing_interned;
Expand Down Expand Up @@ -508,3 +512,27 @@ ZEND_API zend_string *zend_string_concat3(

return res;
}

/* strlcpy and strlcat are not intercepted by msan, so we need to do it ourselves. */
#if __has_feature(memory_sanitizer)
static size_t (*libc_strlcpy)(char *__restrict, const char *__restrict, size_t);
size_t strlcpy(char *__restrict dest, const char *__restrict src, size_t n)
{
if (!libc_strlcpy) {
libc_strlcpy = dlsym(RTLD_NEXT, "strlcpy");
}
size_t result = libc_strlcpy(dest, src, n);
__msan_unpoison_string(dest);
return result;
}
static size_t (*libc_strlcat)(char *__restrict, const char *__restrict, size_t);
size_t strlcat (char *__restrict dest, const char *restrict src, size_t n)
{
if (!libc_strlcat) {
libc_strlcat = dlsym(RTLD_NEXT, "strlcat");
}
size_t result = libc_strlcat(dest, src, n);
__msan_unpoison_string(dest);
return result;
}
#endif