From 269a0961d76c49a464fe9ff22c0fe19578f664fe Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Sun, 5 Mar 2023 12:39:04 +0100 Subject: [PATCH 1/2] Re-enable -Wstrict-aliasing We're not disabling -fstrict-aliasing to it's better to keep this warning. --- Zend/Zend.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index c86aaaa4a7eb5..44c04a9b3e032 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -202,7 +202,7 @@ else AC_DEFINE(ZEND_DEBUG,0,[ ]) fi -test -n "$GCC" && CFLAGS="-Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare $CFLAGS" +test -n "$GCC" && CFLAGS="-Wall -Wextra -Wno-unused-parameter -Wno-sign-compare $CFLAGS" dnl Check if compiler supports -Wno-clobbered (only GCC) AX_CHECK_COMPILE_FLAG([-Wno-clobbered], CFLAGS="-Wno-clobbered $CFLAGS", , [-Werror]) dnl Check for support for implicit fallthrough level 1, also add after previous CFLAGS as level 3 is enabled in -Wextra From 4d35754a2fda4d4788d544ef8763cdbf65f2594b Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Sun, 5 Mar 2023 12:55:59 +0100 Subject: [PATCH 2/2] Remove unnecessary type punnign from mysqli_api.c value is a long. mysql_stmt_attr_get() writes to the most significant byte. Type punning was used to move that byte to the least significant one, which is UB. We can avoid this by simply casting to my_bool (alias of bool). Previously, a comparison against 0 should've been done. --- ext/mysqli/mysqli_api.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 48078c57df091..68b55e1d78d35 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -1799,11 +1799,11 @@ PHP_FUNCTION(mysqli_stmt_attr_get) "MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, " "MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE"); RETURN_THROWS(); - } - + } if (attr == STMT_ATTR_UPDATE_MAX_LENGTH) - value = *((my_bool *)&value); + value = (my_bool)value; + RETURN_LONG((unsigned long)value); } /* }}} */