Bug #67642 [Opn]: getallheaders does not clean array keys
| From: | herve at moulticast dot net | Date: | Fri, 18 Jul 2014 05:43:52 +0000 |
| Subject: | Bug #67642 [Opn]: getallheaders does not clean array keys | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186716@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67642&edit=1
ID: 67642
User updated by: herve at moulticast dot net
Reported by: herve at moulticast dot net
Summary: getallheaders does not clean array keys
Status: Open
Type: Bug
Package: FPM related
Operating System: Linux Debian 3.14-1-amd64
PHP Version: 5.6.0RC2
Block user comment: N
Private report: N
New Comment:
Yes I have these NULL trailing slashes for all keys, here is an example with Firefox sent headers. I
can also confirm that this wasn't present in php5-fpm 5.6.0~rc1+dfsg-1, it occured when I
updated to php5-fpm 5.6.0~rc2+dfsg-3
Key: Host
H => 72 o => 111 s => 115 t => 116 => 0
Key: User-Agent
U => 85 s => 115 e => 101 r => 114 - => 45 A => 65 g => 103 e => 101 n =>
110 t => 116 => 0
Key: Cache-Control
C => 67 a => 97 c => 99 h => 104 e => 101 - => 45 C => 67 o => 111 n =>
110 t => 116 r => 114 o => 111 l => 108 => 0
Key: Accept
A => 65 c => 99 c => 99 e => 101 p => 112 t => 116 => 0
Key: Accept-Language
A => 65 c => 99 c => 99 e => 101 p => 112 t => 116 - => 45 L => 76 a =>
97 n => 110 g => 103 u => 117 a => 97 g => 103 e => 101 => 0
Key: Cookie
C => 67 o => 111 o => 111 k => 107 i => 105 e => 101 => 0
Previous Comments:
------------------------------------------------------------------------
[2014-07-17 21:44:29] yohgaki@php.net
Do you observe trailing NULL chars for all keys?
------------------------------------------------------------------------
[2014-07-17 15:00:27] herve at moulticast dot net
Description:
------------
Running Debian with kernel 3.14-1-amd64
Webserver: NginX 1.6.0
PHP: 5.6.0RC2 FPM
The getallheaders() method does not build a clean array.
When trying to access some values via $arr['key'] it doesn't work because there is a
non printable character '0' that is added at the end of the key.
Test script:
---------------
<?php
// Working example
foreach($_SERVER as $key => $value) {
print('Key: '. $key . ' => ' . $value . "\n");
$key_arr = str_split($key);
foreach($key_arr as $char) {
print($char . ' => ' . ord($char) .' ');
}
print "\n";
}
// Buggy example using getallheaders
$hdrs = getallheaders();
foreach($hdrs as $key => $value) {
print('Key: '. $key . ' => ' . $value . "\n");
$key_arr = str_split($key);
foreach($key_arr as $char) {
print($char . ' => ' . ord($char) .' ');
}
print "\n";
}
?>
Expected result:
----------------
Key for header 'User-Agent' should be (in ASCII):
85 115 101 114 45 65 103 101 110 116
Actual result:
--------------
Key for header 'User-Agent' is (in ASCII):
85 115 101 114 45 65 103 101 110 116 0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67642&edit=1