Created
February 21, 2019 20:18
-
-
Save zlikavac32/385fb0892003b04b84d5edbda97659b3 to your computer and use it in GitHub Desktop.
PHP segfault due to missing argument in printf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| declare(strict_types=1); | |
| pcntl_async_signals(true); | |
| function printNow(): void { | |
| echo (new DateTime())->format('Y-m-d H:i:s'), "\n"; | |
| //echo (new DateTime())->getTimestamp(), "\n"; // no segfault | |
| //$dt = (new DateTime())->format('Y-m-d H:i:s'); echo $dt, "\n"; // no segfault | |
| //$dt = new DateTime(); echo $dt->format('Y-m-d H:i:s'), "\n"; // no segfault | |
| } | |
| function doSleep(int $sleep): void { | |
| while ($sleep = sleep($sleep)); // while (true) {} or for (;$sleep = sleep($sleep);) | |
| //for (; $sleep; $sleep = sleep($sleep)); // no segfault | |
| //while ($sleep) { $sleep = sleep($sleep); } // no segfault | |
| //$i = 0; while ($i < PHP_INT_MAX) { $i++; } // no segfault | |
| } | |
| printNow(); | |
| pcntl_alarm(2); | |
| pcntl_signal(SIGALRM, function () { | |
| throw new Exception(); | |
| }); | |
| try { | |
| doSleep(4); | |
| } catch (Exception $e) { | |
| printf("Caught %s (%s)\n", get_class($e)); // note that argument for second %s is missing | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment