From: ikindred at cox dot net
Operating system: FreeBSD 4.9
PHP version: 4.3.4
PHP Bug Type: PCRE related
Bug description: preg_quote and/or preg_match disrespect embedded null chars in
strings
Description:
------------
At first glance, either or both of the following are bugs:
1. preg_quote does not properly escape the null character (\000).
2. preg_match chokes on patterns containing unescaped null characters.
I personally want to think that preg_match should be able to handle
patterns containing null characters. However, according to Bug #16590,
preg_match's behavior is a feature and not a bug - oh well. (I also
recognize that there may be legitimate performance reasons for disallowing
null chars in patterns.)
I therefore claim that preg_quote is buggy should be fixed. Please note
that:
(a) preg_quote ("a\000b") returns "a\000b", so it is not like preg_quote
is treating the \000 as an end-of-string character (which would result in
"a" being returned). preg_quote is just passing the \000 through without
escaping it.
(b) As far as I can tell, there is no "preg_quote" function in the PCRE
library (specifically, there is no function with "quote" as part of its
name). So, as far as I can tell, PHP cannot blame the PCRE for
preg_quote's buggy behavior.
Many thanks!
Reproduce code:
---------------
<?php
$pattern = "/". preg_quote ("a\000b"). "/";
print "preg_match: ". preg_match ($pattern, "a\000b"). "\n";
?>
Expected result:
----------------
preg_match: 1
Actual result:
--------------
Warning: No ending delimiter '/' found in /<path>/test.php on line 4
preg_match:
--
Edit bug report at http://bugs.php.net/?id=26927&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26927&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26927&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=26927&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=26927&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=26927&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=26927&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=26927&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=26927&r=support
Expected behavior: http://bugs.php.net/fix.php?id=26927&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=26927&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=26927&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=26927&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26927&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=26927&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=26927&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=26927&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=26927&r=float