php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28538 mysql_escape_string adding a VISIBLE \0 to the end of a string
Submitted: 2004-05-27 08:31 UTC Modified: 2004-05-27 08:55 UTC
From: john at web-imagineer dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4CVS-2004-05-27 (stable) OS: SunOS
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: john at web-imagineer dot com
New email:
PHP Version: OS:

 

 [2004-05-27 08:31 UTC] john at web-imagineer dot com
Description:
------------
this would probably make more immediate sense if you look at the code and the output result first, but heres the basics..

this is weird....
1) i have a string: "10,11,12,13,14,"
2) i remove the final comma by doing 
$groupstr[strlen($groupstr)-1]="";
3) i now have "10,11,12,13,14"
4) heres the weird part...i do mysql_escape_string() on it and i get: 10,11,12,13,14\0

basically, a visible \0 what looks like it should be a null is added to the end of the string.


Reproduce code:
---------------
<?
//This is really wacky (the mysql_escape_string output)
$groupstr="10,11,12,13,14,";
print $groupstr."<BR>";	
$groupstr[strlen($groupstr)-1]="";
print $groupstr."<BR>";	
print mysql_escape_string($groupstr);
			
print "<BR><BR><BR>";

//This works fine			
$groupstr="10,11,12,13,14,";
print $groupstr."<BR>";	
$groupstr=substr($groupstr,0,strlen($groupstr)-1);
print $groupstr."<BR>";	
print mysql_escape_string($groupstr);		
?>

Expected result:
----------------
10,11,12,13,14,
10,11,12,13,14
10,11,12,13,14


10,11,12,13,14,
10,11,12,13,14
10,11,12,13,14 

Actual result:
--------------
10,11,12,13,14,
10,11,12,13,14
10,11,12,13,14\0


10,11,12,13,14,
10,11,12,13,14
10,11,12,13,14 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-27 08:55 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You're setting a *character* to an empty string, which evaluates as 0 here. Use chop() or similar to get rid of it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC