note 93170 added to function.substr-count
| From: | chrisstocktonaz at gmail dot com | Date: | Wed, 26 Aug 2009 23:52:21 +0000 |
| Subject: | note 93170 added to function.substr-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159911@lists.php.net to get a copy of this message | ||
In regards to anyone thinking of using code contributed by zmindster at gmail dot com
Please take careful consideration of possible edge cases with that regex, in example:
$url = 'http://w3.host.tld/path/to/file/..../file.extension';
$url = 'http://w3.host.tld/path/to/file/../file.extension?malicous=....';
This would cause a infinite loop and for example be a possible entry point for a denial of service
attack. A correct fix would require additional code, a quick hack would be just adding a additional
check, without clarity or performance in mind:
...
$i = 0;
while (substr_count($url, '../') && ++$i < strlen($url))
...
-Chris
----
Server IP: 209.41.74.194
Probable Submitter: 64.202.160.65
----
Manual Page -- http://www.php.net/manual/en/function.substr-count.php
Edit -- https://master.php.net/note/edit/93170
Del: integrated -- https://master.php.net/note/delete/93170/integrated
Del: useless -- https://master.php.net/note/delete/93170/useless
Del: bad code -- https://master.php.net/note/delete/93170/bad+code
Del: spam -- https://master.php.net/note/delete/93170/spam
Del: non-english -- https://master.php.net/note/delete/93170/non-english
Del: in docs -- https://master.php.net/note/delete/93170/in+docs
Del: other reasons-- https://master.php.net/note/delete/93170
Reject -- https://master.php.net/note/reject/93170
Search -- https://master.php.net/manage/user-notes.php