Skip to content

Commit d5359ac

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Intercept strlcpy and strlcat for msan on Clang 17 (#12674)
2 parents 94f5ef0 + 99504aa commit d5359ac

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Zend/zend_string.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
# include "valgrind/callgrind.h"
2424
#endif
2525

26+
#if __has_feature(memory_sanitizer)
27+
# include <sanitizer/msan_interface.h>
28+
#endif
29+
2630
ZEND_API zend_new_interned_string_func_t zend_new_interned_string;
2731
ZEND_API zend_string_init_interned_func_t zend_string_init_interned;
2832
ZEND_API zend_string_init_existing_interned_func_t zend_string_init_existing_interned;
@@ -500,3 +504,27 @@ ZEND_API zend_string *zend_string_concat3(
500504

501505
return res;
502506
}
507+
508+
/* strlcpy and strlcat are not intercepted by msan, so we need to do it ourselves. */
509+
#if __has_feature(memory_sanitizer)
510+
static size_t (*libc_strlcpy)(char *__restrict, const char *__restrict, size_t);
511+
size_t strlcpy(char *__restrict dest, const char *__restrict src, size_t n)
512+
{
513+
if (!libc_strlcpy) {
514+
libc_strlcpy = dlsym(RTLD_NEXT, "strlcpy");
515+
}
516+
size_t result = libc_strlcpy(dest, src, n);
517+
__msan_unpoison_string(dest);
518+
return result;
519+
}
520+
static size_t (*libc_strlcat)(char *__restrict, const char *__restrict, size_t);
521+
size_t strlcat (char *__restrict dest, const char *restrict src, size_t n)
522+
{
523+
if (!libc_strlcat) {
524+
libc_strlcat = dlsym(RTLD_NEXT, "strlcat");
525+
}
526+
size_t result = libc_strlcat(dest, src, n);
527+
__msan_unpoison_string(dest);
528+
return result;
529+
}
530+
#endif

0 commit comments

Comments
 (0)