php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67642 getallheaders does not clean array keys
Submitted: 2014-07-17 15:00 UTC Modified: 2017-01-29 04:22 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: herve at moulticast dot net Assigned:
Status: No Feedback Package: FPM related
PHP Version: 5.6.0RC2 OS: Linux Debian 3.14-1-amd64
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-07-17 15:00 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-07-17 21:44 UTC] yohgaki@php.net
Do you observe trailing NULL chars for all keys?
 [2014-07-18 05:43 UTC] herve at moulticast dot net
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
 [2014-07-21 01:10 UTC] yohgaki@php.net
-Status: Open +Status: Verified
 [2014-07-21 01:10 UTC] yohgaki@php.net
PHP array keys must be null terminated. It seems key length is too long by 1.
 [2014-07-21 07:37 UTC] arjen at react dot com
getallheaders is not implemented in vanilla PHP 5.6, see https://github.com/php/php-src/blob/PHP-5.6/sapi/fpm/fpm/fpm_main.c

Debian is applying some patches, which they want to be merged into mainline PHP: https://github.com/php/php-src/pull/721/files

Think this issue should be reported by Debian and/or fix and merge the PR.
 [2017-01-15 07:21 UTC] krakjoe@php.net
-Status: Verified +Status: Feedback
 [2017-01-15 07:21 UTC] krakjoe@php.net
We are awaiting feedback on https://github.com/php/php-src/pull/910 which implements getallheaders in FPM, and may be targeting 7.
 [2017-01-29 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC