php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70546 ext/sysvshm: two broken tests on Solaris
Submitted: 2015-09-21 14:40 UTC Modified: -
From: rainer dot jung at kippdata dot de Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 7.0.0RC3 OS: Solaris
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rainer dot jung at kippdata dot de
New email:
PHP Version: OS:

 

 [2015-09-21 14:40 UTC] rainer dot jung at kippdata dot de
Description:
------------
Tests ext/sysvshm/tests/002.phpt and ext/sysvshm/tests/007.phpt are both broken on Solaris. Solaris does not allow to remove a shred memory segment twice in the same process. So when doing two calls to shm_remove() for the same segment, the second fails with errno 22 (Invalid argument). This can easily be reproduced using a simple C program. On linux calling shm_remove() twice is allowed. The standards docs for shmctl with param IPC_RMID (that is what sits underneath PHP shm_remove()) say:

<quote>Remove the shared memory identifier specified by shmid from the system and destroy the shared memory segment and shmid_ds data structure associated with it. IPC_RMID can only be executed by a process that has an effective user ID equal to either that of a process with appropriate privileges or to the value of shm_perm.cuid or shm_perm.uid in the shmid_ds data structure associated with shmid.</quote>

So IMHO the linux behavior is more luck than expected.

The problem shows up in ext/sysvshm/tests/002.phpt, failing because of the output

Warning: shm_remove(): failed for key 0x7406e291, id -37354056: Invalid argument in /path/to/ext/sysvshm/tests/002.php on line 21

I think that failure might be actually side effect of a typo. The test contains:

     19 var_dump($s = shm_attach($key, -1));
     20 shm_remove($s);
     21 var_dump(shm_attach($key, 0));
     22 shm_remove($s);

and if you alter it to

     19 var_dump($s = shm_attach($key, -1));
     20 shm_remove($s);
     21 var_dump($s = shm_attach($key, 0));
     22 shm_remove($s);


(adding "$s = " for the second shm_attach) the test passes.

The second failing test is ext/sysvshm/tests/007.phpt. The message is

Warning: shm_remove(): failed for key 0x7406ef15, id -37354344: Invalid argument in /path/to/ext/sysvshm/tests/007.php on line 12

and the problem is:

     10
     11 var_dump(shm_remove($s));
     12 var_dump(shm_remove($s));
     13

so the test tries to remove the same shm twice. That might be intended, but it is not guaranteed to work on all platforms. I don't actually see a reason for that part of the test, so I suggets to drop line 12.

Please see the attached patch with the fixes for the two tests.

The problem and patch applies to the latest releases of PHP 5.4-5.6 and 7 RC 3.



Patches

php-sysvshm-shm_remove-twice (last revision 2015-09-21 14:42 UTC by rainer dot jung at kippdata dot de)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-09-22 04:07 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b8ea991821753898ba30fa170b25eadd3fc703b2
Log: Fixed bug #70546 (ext/sysvshm: two broken tests on Solaris) by rainer.jung
 [2015-09-22 04:07 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2015-09-29 13:10 UTC] ab@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b8ea991821753898ba30fa170b25eadd3fc703b2
Log: Fixed bug #70546 (ext/sysvshm: two broken tests on Solaris) by rainer.jung
 [2016-07-20 11:36 UTC] davey@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b8ea991821753898ba30fa170b25eadd3fc703b2
Log: Fixed bug #70546 (ext/sysvshm: two broken tests on Solaris) by rainer.jung
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Nov 30 14:05:55 2022 UTC