[PHP-CVS] [php-src] master: Prevents tests from leaking System V IPC objects (#22912)
[email protected] (NickSdot via GitHub) Thu, 30 Jul 2026 13:50:17 +0000
| Newsgroups | php.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: NickSdot (NickSdot)
Committer: GitHub (web-flow)
Pusher: iliaal
Date: 2026-07-30T09:50:14-04:00
Commit: https://github.com/php/php-src/commit/61a190cdd2e0020cbecf46c4b42525a8dca0cb4c
Raw diff: https://github.com/php/php-src/commit/61a190cdd2e0020cbecf46c4b42525a8dca0cb4c.diff
Prevents tests from leaking System V IPC objects (#22912)
* Clean up IPC objects in arginfo mismatch test
* Fix GH-16592 test leaking a message queue
Changed paths:
M Zend/tests/arginfo_zpp_mismatch.phpt
M ext/sysvmsg/tests/gh16592.phpt
Diff:
diff --git a/Zend/tests/arginfo_zpp_mismatch.phpt b/Zend/tests/arginfo_zpp_mismatch.phpt
index d7aefc6f374f..94f6b070900e 100644
--- a/Zend/tests/arginfo_zpp_mismatch.phpt
+++ b/Zend/tests/arginfo_zpp_mismatch.phpt
@@ -10,6 +10,36 @@ if (getenv('SKIP_MSAN')) die("skip msan misses interceptors for some functions")
require __DIR__ . "/arginfo_zpp_mismatch.inc";
+function testWeakSysvIpcFunction($function): bool {
+ if (!in_array($function, ['msg_queue_exists', 'msg_get_queue', 'sem_get', 'shm_attach'], true)) {
+ return false;
+ }
+
+ for ($argumentCount = 0; $argumentCount <= 8; $argumentCount++) {
+ $arguments = array_fill(0, $argumentCount, null);
+ if ($function === 'msg_queue_exists' && $argumentCount >= 1) {
+ $arguments[0] = 1;
+ }
+ if (($function === 'sem_get' || $function === 'shm_attach') && $argumentCount >= 3) {
+ $arguments[2] = 0600;
+ }
+
+ try {
+ $result = @$function(...$arguments);
+ if ($result instanceof SysvMessageQueue) {
+ msg_remove_queue($result);
+ } elseif ($result instanceof SysvSemaphore) {
+ sem_remove($result);
+ } elseif ($result instanceof SysvSharedMemory) {
+ shm_remove($result);
+ }
+ } catch (Throwable) {
+ }
+ }
+
+ return true;
+}
+
function test($function) {
if (skipFunction($function)) {
return;
@@ -21,6 +51,10 @@ function test($function) {
} else {
echo "Testing " . get_class($function[0]) . "::$function[1]\n";
}
+ if (testWeakSysvIpcFunction($function)) {
+ ob_end_clean();
+ return;
+ }
try {
@$function();
} catch (Throwable) {
diff --git a/ext/sysvmsg/tests/gh16592.phpt b/ext/sysvmsg/tests/gh16592.phpt
index 8490d000f891..d48927b4dfee 100644
--- a/ext/sysvmsg/tests/gh16592.phpt
+++ b/ext/sysvmsg/tests/gh16592.phpt
@@ -8,11 +8,14 @@ class Test {
function __serialize() {}
}
-$q = msg_get_queue(1);
+// use a private queue, so we only remove our own.
+$q = msg_get_queue(0, 0600);
try {
msg_send($q, 1, new Test, true);
} catch (\TypeError $e) {
echo $e->getMessage();
+} finally {
+ msg_remove_queue($q);
}
?>
--EXPECT--