mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Intercept strlcpy and strlcat for msan on Clang 17 (#12674)
This commit is contained in:
parent
d966c296d0
commit
99504aa148
1 changed files with 28 additions and 0 deletions
|
@ -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;
|
||||
|
@ -490,3 +494,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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue