php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #920 printf will not echo out NULL byte
Submitted: 1998-11-15 02:20 UTC Modified: 1998-11-15 03:07 UTC
From: jordy at wserv dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.4 OS: Linux
Private report: No CVE-ID: None
 [1998-11-15 02:20 UTC] jordy at wserv dot com
This should print out a NULL byte to the web browser, however it doesn't print anything. The same code in C and Perl will print a NULL byte out to the web browser. This is required to implement special protocols which require NULL bytes to be sent out.

# cat test.php3
<?php
   printf("%c", 0);
?>

# socket -v localhost 80 > output
connected to localhost port 80 (http)
GET /test.php3 HTTP/1.0

# cat -A output
HTTP/1.1 200 OK^M$
Date: Sun, 15 Nov 1998 07:18:42 GMT^M$
Server: Apache/1.3.2 (Unix) PHP/3.0.4 FrontPage/3.0.4.2 mod_ssl/2.0.11 SSLeay/0.9.0b^M$
Connection: close^M$
Content-Type: text/html^M$
^M$

# cat test.pl
#!/usr/bin/perl

print "Content-type: text/html\n\n";

printf("%c", 0);

# socket -v localhost 80 > output
connected to localhost port 80 (http)
GET /test.pl HTTP/1.0

# cat -A output
HTTP/1.1 200 OK^M$
Date: Sun, 15 Nov 1998 07:19:53 GMT^M$
Server: Apache/1.3.2 (Unix) PHP/3.0.4 FrontPage/3.0.4.2 mod_ssl/2.0.11 SSLeay/0.9.0b^M$
Connection: close^M$
Content-Type: text/html^M$
^M$
^@

Note the ^@ at the end.. it is the NULL which the PERL script prints, but the PHP script does not. 

echo() does not have this same problem:

# cat test.php3
<?php
  echo chr(0);
?>

# socket -v localhost 80 > output
connected to localhost port 80 (http)
GET /test.php3 HTTP/1.0

# cat -A output
HTTP/1.1 200 OK^M$
Date: Sun, 15 Nov 1998 07:23:02 GMT^M$
Server: Apache/1.3.2 (Unix) PHP/3.0.4 FrontPage/3.0.4.2 mod_ssl/2.0.11 SSLeay/0.9.0b^M$
Connection: close^M$
Content-Type: text/html^M$
^M$
^@

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-11-15 03:07 UTC] rasmus
Fixed - You can grab the patch from:
http://cvs.php.net/cvsweb.cgi/functions/formatted_print.c.diff?r1=1.41&r2=1.42
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 11:01:32 2024 UTC