From c218f629202cfc618d84dff6a5573e81c7f60540 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Tue, 21 Jan 2025 19:20:57 +0100 Subject: [PATCH 1/4] Remove always-true check in pdo_stmt.c (#17535) `check_empty` is checked earlier up, so this variable is always true. --- ext/pdo/pdo_stmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 0c115c24cf2b6..dc0b952a86f18 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -2360,7 +2360,7 @@ static int row_dim_exists(zend_object *object, zval *offset, int check_empty) return false; } ZEND_ASSERT(retval == &tmp_val); - bool res = check_empty ? i_zend_is_true(retval) : Z_TYPE(tmp_val) != IS_NULL; + bool res = i_zend_is_true(retval); zval_ptr_dtor_nogc(retval); return res; } else { From 0b3e637aec21dabbc797f89c6b68e5bc208f0743 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Tue, 21 Jan 2025 08:36:20 +0100 Subject: [PATCH 2/4] Fix may_have_extra_named_args flag for ZEND_AST_UNPACK The check for `!fbc || (fbc->common.fn_flags & ZEND_ACC_VARIADIC)` is performed after `fbc` is set to NULL, so this always returns true. This results in `ZEND_FCALL_MAY_HAVE_EXTRA_NAMED_PARAMS` always being set for unpack sends. Fix it by moving the flag updates to the point before setting `fbc` to NULL. Closes GH-17534. --- NEWS | 1 + Zend/zend_compile.c | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 9b1fc5f854180..6744e7ed5b865 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ PHP NEWS . Fixed potential OOB when checking for trailing spaces on Windows. (cmb) . Fixed bug GH-17408 (Assertion failure Zend/zend_exceptions.c). (nielsdos, ilutov) + . Fix may_have_extra_named_args flag for ZEND_AST_UNPACK. (nielsdos) - DOM: . Fixed bug GH-17500 (Segfault with requesting nodeName on nameless doctype). diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index a78523d493f71..dbd8c9dc17fd7 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -3661,6 +3661,12 @@ static uint32_t zend_compile_args( "Cannot use argument unpacking after named arguments"); } + /* Unpack may contain named arguments. */ + may_have_undef = 1; + if (!fbc || (fbc->common.fn_flags & ZEND_ACC_VARIADIC)) { + *may_have_extra_named_args = 1; + } + uses_arg_unpack = 1; fbc = NULL; @@ -3669,11 +3675,6 @@ static uint32_t zend_compile_args( opline->op2.num = arg_count; opline->result.var = EX_NUM_TO_VAR(arg_count - 1); - /* Unpack may contain named arguments. */ - may_have_undef = 1; - if (!fbc || (fbc->common.fn_flags & ZEND_ACC_VARIADIC)) { - *may_have_extra_named_args = 1; - } continue; } From aa76127d017cda4975e307d38c5572ac02ce3635 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 21 Jan 2025 20:05:29 +0100 Subject: [PATCH 3/4] Address more Clang warnings (GH-17506) We prefer clean solutions (such as declaring the proper type in the first place, or introducing a portable format specifier) where easily possible, but resort to casts otherwise. We also port https://github.com/libgd/libgd/commit/f1480ab14bd5e2e4b4d83d8f3e64e786aa810637. --- ext/com_dotnet/com_handlers.c | 2 +- ext/ffi/ffi.c | 3 +++ ext/gd/libgd/gd_interpolation.c | 5 ----- ext/libxml/libxml.c | 4 ++-- ext/mysqlnd/mysqlnd_auth.c | 10 +++++----- ext/mysqlnd/mysqlnd_connection.c | 2 +- ext/openssl/xp_ssl.c | 2 +- ext/standard/streamsfuncs.c | 2 +- main/php_network.h | 2 ++ win32/registry.c | 4 ++-- win32/wsyslog.c | 4 ++-- 11 files changed, 20 insertions(+), 20 deletions(-) diff --git a/ext/com_dotnet/com_handlers.c b/ext/com_dotnet/com_handlers.c index a5c68bb7b9987..fcbae4e34621f 100644 --- a/ext/com_dotnet/com_handlers.c +++ b/ext/com_dotnet/com_handlers.c @@ -353,7 +353,7 @@ static zend_function *com_method_get(zend_object **object_ptr, zend_string *name ITypeComp_Release(bindptr.lptcomp); break; - case DESCKIND_NONE: + default: break; } if (TI) { diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index c8e0035b3ac91..3fc97577abdea 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -900,6 +900,9 @@ static zend_always_inline zend_string *zend_ffi_mangled_func_name(zend_string *n case FFI_VECTORCALL_PARTIAL: return strpprintf(0, "%s@@%zu", ZSTR_VAL(name), zend_ffi_arg_size(type)); # endif + default: + /* other calling conventions don't apply name mangling */ + break; } #endif return zend_string_copy(name); diff --git a/ext/gd/libgd/gd_interpolation.c b/ext/gd/libgd/gd_interpolation.c index 9b0551c7afc8e..f8ba9087910fc 100644 --- a/ext/gd/libgd/gd_interpolation.c +++ b/ext/gd/libgd/gd_interpolation.c @@ -62,11 +62,6 @@ #include "gdhelpers.h" #include "gd_intern.h" -#ifdef _MSC_VER -# pragma optimize("t", on) -# include -#endif - static gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height); diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index 40b6326ba72c4..94704d09e463e 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -433,9 +433,9 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char if (strncasecmp(resolved_path, "file:/", pre_len) == 0 && '/' != resolved_path[pre_len]) { - xmlChar *tmp = xmlStrdup(resolved_path + pre_len); + xmlChar *tmp = xmlStrdup(BAD_CAST (resolved_path + pre_len)); xmlFree(resolved_path); - resolved_path = tmp; + resolved_path = (char *) tmp; } } #endif diff --git a/ext/mysqlnd/mysqlnd_auth.c b/ext/mysqlnd/mysqlnd_auth.c index ea9755c982ed8..3a30b1458dea0 100644 --- a/ext/mysqlnd/mysqlnd_auth.c +++ b/ext/mysqlnd/mysqlnd_auth.c @@ -746,7 +746,7 @@ static mysqlnd_rsa_t mysqlnd_sha256_get_rsa_from_pem(const char *buf, size_t len) { BCRYPT_KEY_HANDLE ret = 0; - LPSTR der_buf = NULL; + BYTE *der_buf = NULL; DWORD der_len; CERT_PUBLIC_KEY_INFO *key_info = NULL; DWORD key_info_len; @@ -789,7 +789,7 @@ mysqlnd_sha256_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t server_pub ZeroMemory(&padding_info, sizeof padding_info); padding_info.pszAlgId = BCRYPT_SHA1_ALGORITHM; - if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info, + if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, (zend_uchar *) xor_str, passwd_len + 1, &padding_info, NULL, 0, NULL, 0, &server_public_key_len, BCRYPT_PAD_OAEP)) { DBG_RETURN(0); } @@ -809,7 +809,7 @@ mysqlnd_sha256_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t server_pub *auth_data_len = server_public_key_len; ret = malloc(*auth_data_len); - if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info, + if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, (zend_uchar *) xor_str, passwd_len + 1, &padding_info, NULL, 0, ret, server_public_key_len, &server_public_key_len, BCRYPT_PAD_OAEP)) { BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key); DBG_RETURN(0); @@ -1052,7 +1052,7 @@ mysqlnd_caching_sha2_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t serv ZeroMemory(&padding_info, sizeof padding_info); padding_info.pszAlgId = BCRYPT_SHA1_ALGORITHM; - if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info, + if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, (zend_uchar *) xor_str, passwd_len + 1, &padding_info, NULL, 0, NULL, 0, &server_public_key_len, BCRYPT_PAD_OAEP)) { DBG_RETURN(0); } @@ -1071,7 +1071,7 @@ mysqlnd_caching_sha2_public_encrypt(MYSQLND_CONN_DATA * conn, mysqlnd_rsa_t serv } *crypted = emalloc(server_public_key_len); - if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, xor_str, passwd_len + 1, &padding_info, + if (BCryptEncrypt((BCRYPT_KEY_HANDLE) server_public_key, (zend_uchar *) xor_str, passwd_len + 1, &padding_info, NULL, 0, *crypted, server_public_key_len, &server_public_key_len, BCRYPT_PAD_OAEP)) { BCryptDestroyKey((BCRYPT_KEY_HANDLE) server_public_key); DBG_RETURN(0); diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c index 8582e376e92a6..2787b32931747 100644 --- a/ext/mysqlnd/mysqlnd_connection.c +++ b/ext/mysqlnd/mysqlnd_connection.c @@ -2241,7 +2241,7 @@ mysqlnd_poll(MYSQLND **r_array, MYSQLND **e_array, MYSQLND ***dont_poll, long se retval = php_select(max_fd + 1, &rfds, &wfds, &efds, tv_p); if (retval == -1) { - php_error_docref(NULL, E_WARNING, "Unable to select [%d]: %s (max_fd=%d)", + php_error_docref(NULL, E_WARNING, "Unable to select [%d]: %s (max_fd=" PHP_SOCKET_FMT ")", errno, strerror(errno), max_fd); DBG_RETURN(FAIL); } diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index eb7ab93815a9c..484abf483539d 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -700,7 +700,7 @@ static int php_openssl_win_cert_verify_callback(X509_STORE_CTX *x509_store_ctx, err_code = e; } - php_error_docref(NULL, E_WARNING, "Error encoding X509 certificate: %d: %s", err_code, ERR_error_string(err_code, err_buf)); + php_error_docref(NULL, E_WARNING, "Error encoding X509 certificate: %lu: %s", err_code, ERR_error_string(err_code, err_buf)); RETURN_CERT_VERIFY_FAILURE(SSL_R_CERTIFICATE_VERIFY_FAILED); } diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index 1929075b60b71..4f9a7106c01c1 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -859,7 +859,7 @@ PHP_FUNCTION(stream_select) retval = php_select(max_fd+1, &rfds, &wfds, &efds, tv_p); if (retval == -1) { - php_error_docref(NULL, E_WARNING, "Unable to select [%d]: %s (max_fd=%d)", + php_error_docref(NULL, E_WARNING, "Unable to select [%d]: %s (max_fd=" PHP_SOCKET_FMT ")", errno, strerror(errno), max_fd); RETURN_FALSE; } diff --git a/main/php_network.h b/main/php_network.h index 0a0da4cf7084a..94a2508c89e52 100644 --- a/main/php_network.h +++ b/main/php_network.h @@ -96,8 +96,10 @@ END_EXTERN_C() #ifdef PHP_WIN32 typedef SOCKET php_socket_t; +#define PHP_SOCKET_FMT "%" PRIxPTR #else typedef int php_socket_t; +#define PHP_SOCKET_FMT "%d" #endif #ifdef PHP_WIN32 diff --git a/win32/registry.c b/win32/registry.c index cd9fc38c199fe..81378b0f46a5e 100644 --- a/win32/registry.c +++ b/win32/registry.c @@ -94,7 +94,7 @@ static int LoadDirectory(HashTable *directories, HKEY key, char *path, int path_ memset(name, '\0', max_name+1); memset(value, '\0', max_value+1); - if (RegEnumValue(key, i, name, &name_len, NULL, &type, value, &value_len) == ERROR_SUCCESS) { + if (RegEnumValue(key, i, name, &name_len, NULL, &type, (LPBYTE) value, &value_len) == ERROR_SUCCESS) { if ((type == REG_SZ) || (type == REG_EXPAND_SZ)) { zval data; @@ -287,7 +287,7 @@ char *GetIniPathFromRegistry() if (OpenPhpRegistryKey(NULL, &hKey)) { DWORD buflen = MAXPATHLEN; reg_location = emalloc(MAXPATHLEN+1); - if(RegQueryValueEx(hKey, PHPRC_REGISTRY_NAME, 0, NULL, reg_location, &buflen) != ERROR_SUCCESS) { + if(RegQueryValueEx(hKey, PHPRC_REGISTRY_NAME, 0, NULL, (LPBYTE) reg_location, &buflen) != ERROR_SUCCESS) { RegCloseKey(hKey); efree(reg_location); reg_location = NULL; diff --git a/win32/wsyslog.c b/win32/wsyslog.c index b4e58b15629a7..0cf3c263bc3a0 100644 --- a/win32/wsyslog.c +++ b/win32/wsyslog.c @@ -89,7 +89,7 @@ void syslog(int priority, const char *message, ...) void vsyslog(int priority, const char *message, va_list args) { - LPTSTR strs[2]; + LPCSTR strs[2]; unsigned short etype; char *tmp = NULL; DWORD evid; @@ -120,7 +120,7 @@ void vsyslog(int priority, const char *message, va_list args) /* report the event */ if (strsw[0] && strsw[1]) { - ReportEventW(PW32G(log_source), etype, (unsigned short) priority, evid, NULL, 2, 0, strsw, NULL); + ReportEventW(PW32G(log_source), etype, (unsigned short) priority, evid, NULL, 2, 0, (LPCWSTR *) strsw, NULL); free(strsw[0]); free(strsw[1]); efree(tmp); From fa21fce84f758faa5558adcd1d957bb9a9f7039e Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Tue, 21 Jan 2025 18:11:49 +0100 Subject: [PATCH 4/4] ext/pgsql: Add check for constant PGRES_TUPLES_CHUNK to fix compilation failures close GH-17540 --- NEWS | 4 ++++ ext/pgsql/config.m4 | 14 +++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 7d73004ed7015..25bdde9676a18 100644 --- a/NEWS +++ b/NEWS @@ -65,6 +65,10 @@ PHP NEWS the cpu mask argument with entries type different than int/string. (David Carlier) +- PgSql: + . Fixed build failure when the constant PGRES_TUPLES_CHUNK is not present + in the system. (chschneider) + - Phar: . Fixed bug GH-17518 (offset overflow phar extractTo()). (nielsdos) diff --git a/ext/pgsql/config.m4 b/ext/pgsql/config.m4 index 8718208e85061..e4d63b98bc72c 100644 --- a/ext/pgsql/config.m4 +++ b/ext/pgsql/config.m4 @@ -28,15 +28,19 @@ if test "$PHP_PGSQL" != "no"; then [Define to 1 if libpq has the 'PQsocketPoll' function (PostgreSQL 17 or later).])],, [$PGSQL_LIBS]) - PHP_CHECK_LIBRARY([pq], [PQsetChunkedRowsMode], - [AC_DEFINE([HAVE_PG_SET_CHUNKED_ROWS_SIZE], [1], - [Define to 1 if libpq has the 'PQsetChunkedRowsMode' function (PostgreSQL - 17 or later).])],, - [$PGSQL_LIBS]) old_CFLAGS=$CFLAGS CFLAGS="$CFLAGS $PGSQL_CFLAGS" + AC_CHECK_DECLS([PGRES_TUPLES_CHUNK], + PHP_CHECK_LIBRARY([pq], [PQsetChunkedRowsMode], + [AC_DEFINE([HAVE_PG_SET_CHUNKED_ROWS_SIZE], [1], + [Define to 1 if libpq has the 'PQsetChunkedRowsMode' function (PostgreSQL + 17 or later).])],, + [$PGSQL_LIBS]),, + [#include ] + ) + dnl Available since PostgreSQL 12. AC_CACHE_CHECK([if PGVerbosity enum has PQERRORS_SQLSTATE], [php_cv_enum_pgverbosity_pqerrors_sqlstate],