From fab0a6d75cbc5730a4d57cf4ebb8fa45363d0811 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Tue, 27 May 2025 20:40:35 +0200 Subject: [PATCH] Backport fix for GH-17687 Introducing a new attribute macro in lower branches is an ABI break and not allowed. However, we still need to fix the warnings such that -Werror builds don't break. So we copy the macro from the master branch to the C files in the appropriate places. --- ext/fileinfo/data_file.c | 2 +- ext/fileinfo/libmagic/apprentice.c | 6 ++++++ ext/pdo/pdo_sqlstate.c | 8 +++++++- ext/standard/crypt_sha256.c | 8 +++++++- ext/standard/crypt_sha512.c | 8 +++++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ext/fileinfo/data_file.c b/ext/fileinfo/data_file.c index 212addc4d05..af4c139bed0 100644 --- a/ext/fileinfo/data_file.c +++ b/ext/fileinfo/data_file.c @@ -1,6 +1,6 @@ /* This is a generated file, do not modify */ /* Usage: php create_data_file.php /path/to/magic.mgc > data_file.c */ -const unsigned char php_magic_database[7955032] = { +const unsigned char php_magic_database[7955032] ZEND_NONSTRING = { 0x1C, 0x04, 0x1E, 0xF1, 0x12, 0x00, 0x00, 0x00, 0xD2, 0x3B, 0x00, 0x00, 0xD2, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/ext/fileinfo/libmagic/apprentice.c b/ext/fileinfo/libmagic/apprentice.c index 5a5ae197467..922adcf55f1 100644 --- a/ext/fileinfo/libmagic/apprentice.c +++ b/ext/fileinfo/libmagic/apprentice.c @@ -185,6 +185,12 @@ private struct { { NULL, 0, NULL } }; +#if __has_attribute(nonstring) +# define ZEND_NONSTRING __attribute__((nonstring)) +#else +# define ZEND_NONSTRING +#endif + #include "../data_file.c" #ifdef COMPILE_ONLY diff --git a/ext/pdo/pdo_sqlstate.c b/ext/pdo/pdo_sqlstate.c index 5858566a818..a5e23890cee 100644 --- a/ext/pdo/pdo_sqlstate.c +++ b/ext/pdo/pdo_sqlstate.c @@ -24,8 +24,14 @@ #include "php_pdo.h" #include "php_pdo_driver.h" +#if __has_attribute(nonstring) +# define ZEND_NONSTRING __attribute__((nonstring)) +#else +# define ZEND_NONSTRING +#endif + struct pdo_sqlstate_info { - const char state[5]; + const char state[5] ZEND_NONSTRING; const char *desc; }; diff --git a/ext/standard/crypt_sha256.c b/ext/standard/crypt_sha256.c index 9e86db6020c..3e99bedc541 100644 --- a/ext/standard/crypt_sha256.c +++ b/ext/standard/crypt_sha256.c @@ -317,8 +317,14 @@ static const char sha256_rounds_prefix[] = "rounds="; /* Maximum number of rounds. */ #define ROUNDS_MAX 999999999 +#if __has_attribute(nonstring) +# define ZEND_NONSTRING __attribute__((nonstring)) +#else +# define ZEND_NONSTRING +#endif + /* Table with characters for base64 transformation. */ -static const char b64t[64] = +static const char b64t[64] ZEND_NONSTRING = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; char * php_sha256_crypt_r(const char *key, const char *salt, char *buffer, int buflen) diff --git a/ext/standard/crypt_sha512.c b/ext/standard/crypt_sha512.c index 6ead7f2964a..ae0eaecdca9 100644 --- a/ext/standard/crypt_sha512.c +++ b/ext/standard/crypt_sha512.c @@ -350,8 +350,14 @@ static const char sha512_rounds_prefix[] = "rounds="; /* Maximum number of rounds. */ #define ROUNDS_MAX 999999999 +#if __has_attribute(nonstring) +# define ZEND_NONSTRING __attribute__((nonstring)) +#else +# define ZEND_NONSTRING +#endif + /* Table with characters for base64 transformation. */ -static const char b64t[64] = +static const char b64t[64] ZEND_NONSTRING = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";