Bug #79691 [Fbk->Opn]: Lack of error checking in `posix_kill`
| From: | srivas41 at purdue dot edu | Date: | Thu, 11 Jun 2020 23:20:04 +0000 |
| Subject: | Bug #79691 [Fbk->Opn]: Lack of error checking in `posix_kill` | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227428@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79691&edit=1
ID: 79691
User updated by: srivas41 at purdue dot edu
Reported by: srivas41 at purdue dot edu
Summary: Lack of error checking in
posix_kill
-Status: Feedback
+Status: Open
Type: Bug
Package: POSIX related
Operating System: Ubuntu 16.04
PHP Version: 7.4.7
Block user comment: N
Private report: N
New Comment:
Could you specify which set of configuration flags enables PHP to warn about the undefined variable
in this specific case? I built with ./buildconf && ./configure --enable-werror
&& make -jnproc`. No error or warning was emitted while running the test script.
Previous Comments:
------------------------------------------------------------------------
[2020-06-11 23:02:23] requinix@php.net
PHP does warn about the undefined variable. If you can't see the warning then you don't
have the appropriate error settings enabled.
------------------------------------------------------------------------
[2020-06-11 22:48:43] srivas41 at purdue dot edu
Description:
------------
Posix_kill lacks error checking for undefined variables passed and instead gets
typecasted to 0 somehow owing to the internal implementation. As specified in the
kill(2) manpage, If pid equals 0, then sig is sent to every process in the process group of
the calling process. Therefore, posix_kill will incorrectly send the signal to
all processes in the process group which includes the interpreter itself.
This behavior can be detrimental if a developer mistakingly passes an undefined variable to
posix_kill. This behavior is reproducible with the script specified below. The script
sends SIGHUP to the interpreter and exits prematurely due to lack of error checking for undefined
variables in posix_kill. Therefore, before printing the last echo statement,
posix_kill passes SIGHUP to the interpreter itself exiting prematurely.
Test script:
---------------
<?php
echo "Testing Posix kill\n";
$signal_number=1; //SIGHUP=1
posix_kill($DUMMY, $signal_number); // $DUMMY is undefined
echo "Posix kill can error check for undefined variables!";
?>
Expected result:
----------------
Ideally, PHP interpreter should raise an error for an undefined variable for the above test script
instead of just weakly typing the undefined variable to 0.
Actual result:
--------------
The message displayed would be something like:
```
Testing Posix kill
[2] <PHP Interpreter PID> hangup ./sapi/cli/php -f test.php
```
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79691&edit=1