Re: How does the PHP Ghost one-liner work?
| From: | Rowan Collins | Date: | Fri, 30 Jan 2015 19:17:34 +0000 |
| Subject: | Re: How does the PHP Ghost one-liner work? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-81449@lists.php.net to get a copy of this message | ||
On 30/01/2015 18:42, Robert Williams wrote:
% php -r '$e="0";for($i=0;$i<2500;$i++){$e="0$e";} gethostbyname($e);’ What’s not being discussed is how it works. From the naive viewpoint of a PHP end-user, I’d expect this one-liner to have the same effect: % php -r '$e="0$e"; gethostbyname($e);’ But it doesn’t. Can someone familiar with PHP’s internals explain why this code triggers the overflow, and whether it will actually do so reliably?No need to be familiar with the internals, you just need to unroll the loop properly in your head: initialise: $e = "0"; => "0" $i=0: $e = "0$e"; => "0" . "0" => "00" $i=1: $e = "0$e"; => "0" . "00" => "000" and so on until you have 2501 zeroes when $i=2499 As Patrick points out, this is a really weird way of initialising that variable, and is presumably translated from another language by someone who doesn't know PHP. -- Rowan Collins [IMSoP]