Commit ab862f1957f for php
commit ab862f1957f8bd75b84df13922e523c6abcfd42b
Author: hohphu8 <kodoku169@gmail.com>
Date: Wed Dec 2 10:11:03 2026 +0700
ext/sysvshm: Use shm_list_ptr->id in shm_remove() failure warning
In shm_remove(), when shmctl(shm_list_ptr->id, IPC_RMID, NULL) fails, the
warning call reads Z_LVAL_P(shm_id) on the SysvSharedMemory object
parameter (IS_OBJECT, parsed with "O"). Since zend_value.lval shares the
union with zend_value.obj, this prints the raw zend_object * heap pointer
address instead of the shared memory identifier (a leftover from the PHP
8.0 resource-to-object migration).
Pass shm_list_ptr->id (which is already a zend_long matching
ZEND_LONG_FMT) instead of Z_LVAL_P(shm_id). Checked ext/sysvshm,
ext/sysvmsg, and ext/sysvsem for similar leftover Z_LVAL_P() calls on
object arguments and confirmed this is the only occurrence.
Added a regression test, skipped on Linux, Windows, and FreeBSD where
repeated IPC_RMID succeeds while attached, exercised on
macOS/OpenBSD/NetBSD.
Close GH-26022
diff --git a/NEWS b/NEWS
index 63a7da1355f..4df9054c3e4 100644
--- a/NEWS
+++ b/NEWS
@@ -360,6 +360,8 @@ PHP NEWS
- Sysvshm:
. Fixed shm_get_var() not unwrapping top-level references from unserialized
values. (Ho Hoang Phu)
+ . Fixed shm_remove() failure warning printing the object pointer instead of
+ the shared memory id. (Ho Hoang Phu)
- XML:
. Fixed xml_error_string() returning the wrong message for libxml error
diff --git a/ext/sysvshm/sysvshm.c b/ext/sysvshm/sysvshm.c
index 9250db476c4..3e7fe1f9211 100644
--- a/ext/sysvshm/sysvshm.c
+++ b/ext/sysvshm/sysvshm.c
@@ -248,7 +248,7 @@ PHP_FUNCTION(shm_remove)
}
if (shmctl(shm_list_ptr->id, IPC_RMID, NULL) < 0) {
- php_error_docref(NULL, E_WARNING, "Failed for key 0x%x, id " ZEND_LONG_FMT ": %s", shm_list_ptr->key, Z_LVAL_P(shm_id), strerror(errno));
+ php_error_docref(NULL, E_WARNING, "Failed for key 0x%x, id " ZEND_LONG_FMT ": %s", shm_list_ptr->key, shm_list_ptr->id, strerror(errno));
RETURN_FALSE;
}
diff --git a/ext/sysvshm/tests/shm_remove_already_removed.phpt b/ext/sysvshm/tests/shm_remove_already_removed.phpt
new file mode 100644
index 00000000000..f8381819660
--- /dev/null
+++ b/ext/sysvshm/tests/shm_remove_already_removed.phpt
@@ -0,0 +1,40 @@
+--TEST--
+shm_remove() warning prints shared memory id instead of object pointer address
+--EXTENSIONS--
+sysvshm
+--SKIPIF--
+<?php
+if (!function_exists('ftok')) die('skip needs ftok');
+if (PHP_OS_FAMILY === 'Linux' || PHP_OS_FAMILY === 'Windows' || PHP_OS === 'FreeBSD') {
+ die('skip platform allows repeated IPC_RMID while attached');
+}
+?>
+--FILE--
+<?php
+
+$key = ftok(__FILE__, 'r');
+$s = shm_attach($key, 1024);
+
+var_dump(shm_remove($s));
+
+$warning = null;
+set_error_handler(function (int $errno, string $errstr) use (&$warning): bool {
+ $warning = $errstr;
+ return true;
+});
+var_dump(shm_remove($s));
+restore_error_handler();
+
+var_dump(preg_match('/^shm_remove\(\): Failed for key 0x[0-9a-f]+, id (\d+): /', (string) $warning, $m) === 1);
+$id = (int) $m[1];
+var_dump($id >= 0 && $id <= 0x7fffffff);
+
+shm_detach($s);
+echo "Done\n";
+?>
+--EXPECT--
+bool(true)
+bool(false)
+bool(true)
+bool(true)
+Done