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

From: Date: Mon, 26 Mar 2007 10:22:25 +0000
Subject: #40915 [Opn->Asn]: addcslashes has unexpected behavior with binary input / string terminator
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-110787@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:           Open
+Status:           Assigned
 Bug Type:         Strings related
 Operating System: Solaris / OS X
 PHP Version:      5.2.1
-Assigned To:      
+Assigned To:      tony2001


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


Thread (3 messages)

« previous php.bugs (#110787) next »