From 26ca363a1357e63d6aa70dffab0e699fffbbef83 Mon Sep 17 00:00:00 2001 From: Guillaume Outters Date: Wed, 1 Oct 2025 16:18:20 +0200 Subject: [PATCH] Fix broken build on *BSD with MSAN The #if to declare instrumented versions of strlcpy and strlcat was too inclusive on *BSD systems where Clang already provides instrumented strong symbols, resulting in "duplicate symbol" at link-time. Fix GH-20002 Closes GH-20032 --- NEWS | 1 + Zend/zend_string.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 952d122fb9172..36da15cf32b7e 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ PHP NEWS array). (ilutov) . Fixed bug GH-19480 (error_log php.ini cannot be unset when open_basedir is configured). (nielsdos) + . Fixed bug GH-20002 (Broken build on *BSD with MSAN). (outtersg) - Curl: . Fix cloning of CURLOPT_POSTFIELDS when using the clone operator instead diff --git a/Zend/zend_string.c b/Zend/zend_string.c index dfe059359aa53..e9ebee08f4393 100644 --- a/Zend/zend_string.c +++ b/Zend/zend_string.c @@ -505,8 +505,10 @@ 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) +/* strlcpy and strlcat are not always intercepted by msan, so we need to do it + * ourselves. Apply a simple heuristic to determine the platforms that need it. + * See https://github.com/php/php-src/issues/20002. */ +#if __has_feature(memory_sanitizer) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) 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) {