Bug #80849 [NEW]: HTTP Status header truncation

From: Date: Tue, 09 Mar 2021 18:36:51 +0000
Subject: Bug #80849 [NEW]: HTTP Status header truncation
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-232641@lists.php.net to get a copy of this message
From:             ben dot bidner at automattic dot com
Operating system: 
PHP version:      8.0.3
Package:          FPM related
Bug Type:         Bug
Bug description:HTTP Status header truncation

Description:
------------
sapi_cgi_send_headers() (in both sapi/fpm/fpm/fpm_main.c and
sapi/cgi/cgi_main.c) will truncate HTTP Status headers larger than
SAPI_CGI_MAX_HEADER_LENGTH in the following cases, potentially causing
the trailing CR LF to be stripped.

	`len = slprintf(buf, SAPI_CGI_MAX_HEADER_LENGTH, "%s\r\n",
SG(sapi_headers).http_status_line);`
	len = slprintf(buf, sizeof(buf), "Status:%s\r\n", s);
	`len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n",
SG(sapi_headers).http_response_code, err->str);`
	`len = slprintf(buf, sizeof(buf), "Status: %d\r\n",
SG(sapi_headers).http_response_code);`

Removing the CR LFs and explicitly sending them after the header is sent
(as per other headers in the code below this) should be sufficient to
fix?

Test script:
---------------
<?php
header( 'HTTP/1.1 201 ' . str_repeat( 'A', 1011 ), true );
exit;

Actual result:
--------------
The example above will return the following headers

HTTP/1.1 201 AAA...AAAContent-type: text/html; charset=UTF-8
Server: nginx
Date: Tue, 09 Mar 2021 18:06:36 GMT
Connection: keep-alive

-- 
Edit bug report at https://bugs.php.net/bug.php?id=80849&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80849&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80849&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80849&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80849&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80849&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80849&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80849&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80849&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80849&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80849&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80849&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80849&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80849&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80849&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80849&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80849&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80849&r=mysqlcfg


Thread (5 messages)

« previous php.bugs (#232641) next »