#40915 [Asn->Csd]: addcslashes has unexpected behavior with binary input / string terminator

From: Date: Mon, 26 Mar 2007 10:28:34 +0000
Subject: #40915 [Asn->Csd]: addcslashes has unexpected behavior with binary input / string terminator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-110788@lists.php.net to get a copy of this message
ID: 40915 Updated by: tony2001@php.net Reported By: trevor at corevx dot com -Status: Assigned +Status: Closed Bug Type: Strings related Operating System: Solaris / OS X PHP Version: 5.2.1 Assigned To: tony2001 New Comment: This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2007-03-26 06:06:03] trevor at corevx dot com Description: ------------ When the input to addcslashes contains a NULL character (string terminator, \000) the resulting output is terminated at that point if the NULL character is not deliberately escaped. This makes it impossible to use addcslashes for certain special cases with binary data. If fixed it would be a much more powerful tool. Reproduce code: --------------- # Last pair demonstrates issue $str = "a\000z"; echo $str; # => az strlen( $str ); # => 3 addslashes( $str ); # => a\0z strlen( addslashes( $str ) ); # => 4 addcslashes( $str, "\000z" ); # => a\000\z strlen( addcslashes( $str, "\000z" ) ); # => 7 addcslashes( $str, "z" ); # => a strlen( addcslashes( $str, "z" ) ); # => 1 Expected result: ---------------- echo addcslashes( $str, "z" ); # => a\z strlen( addcslashes( $str, "z" ) ); # => 4 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40915&edit=1

« previous php.bugs (#110788) next »