Bug 49427

Summary: mod_cgid and mod_cgi do not return proper value when exceeding LimitRequestBody
Product: Apache httpd-2 Reporter: Norihito Aimoto <aimoto321>
Component: mod_cgiAssignee: Apache HTTPD Bugs Mailing List <bugs>
Severity: normal Keywords: MassUpdate
Priority: P2    
Version: 2.2.15   
Target Milestone: ---   
Hardware: All   
OS: All   

Description Norihito Aimoto 2010-06-11 06:05:19 UTC
I used LimitRequestBody directive and then sent POST request which
size is over the value of LimitRequestBody.
I expected the response of Status 413 with the body which is set for the status.
However I got the Status 413 with the body including not only 413, but also 500.

=== httpd.conf ==
ErrorDocument 413 "413 Error!!"
ErrorDocument 500 "500 Error!!"
LimitRequestBody 10000

[root@localhost bin]# telnet 80
Connected to localhost.localdomain (
Escape character is '^]'.
POST /cgi-bin/print.cgi HTTP/1.1
Host: test
Content-Length: 10001

HTTP/1.1 413 Request Entity Too Large
Date: Fri, 04 Jun 2010 07:16:56 GMT
Server: Apache/2.2.15 (Unix)
Connection: close
Content-Type: text/html; charset=iso-8859-1

413 Error!!500 Error!!Connection closed by foreign host.
[root@localhost bin]#

=== access_log === - - [04/Jun/2010:16:16:56 +0900] "POST /cgi-bin/print.cgi HTTP/1.1" 500 22

=== error_log ===
[Fri Jun 04 16:16:56 2010] [error] [client] Requested content-length of 10001 is larger than the configured limit of 10000
[Fri Jun 04 16:16:56 2010] [error] [client] (-3)Unknown error 4294967293: Error reading request entity data

It happens when you use mod_cgid / mod_cgi and LimitRequestBody.
It might caused by the following mod_cgi's code :

--- L.836-843 in mod_cgi.c ---

        rv = ap_get_brigade(r->input_filters, bb, AP_MODE_READBYTES,
                            APR_BLOCK_READ, HUGE_STRING_LEN);

        if (rv != APR_SUCCESS) {
            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
                          "Error reading request entity data");
            return HTTP_INTERNAL_SERVER_ERROR;

Exceeding LimitRequestBody AP_FILTER_ERROR occurs in ap_get_brigade().
Apache put Status 413's body into the response at that time.

However following code returns HTTP_INTERNAL_SERVER_ERROR.
It means that Apache adds Status 500's body to the response.

I think the code might be like following :


        rv = ap_get_brigade(r->input_filters, bb, AP_MODE_READBYTES,
                            APR_BLOCK_READ, HUGE_STRING_LEN);

        if (rv != APR_SUCCESS) {
		if (rv == AP_FILTER_ERROR)
			return rv;

I mention only mod_cgi, but mod_cgid includes the same issue.
Comment 1 William A. Rowe Jr. 2018-11-07 21:09:11 UTC
Please help us to refine our list of open and current defects; this is a mass update of old and inactive Bugzilla reports which reflect user error, already resolved defects, and still-existing defects in httpd.

As repeatedly announced, the Apache HTTP Server Project has discontinued all development and patch review of the 2.2.x series of releases. The final release 2.2.34 was published in July 2017, and no further evaluation of bug reports or security risks will be considered or published for 2.2.x releases. All reports older than 2.4.x have been updated to status RESOLVED/LATER; no further action is expected unless the report still applies to a current version of httpd.

If your report represented a question or confusion about how to use an httpd feature, an unexpected server behavior, problems building or installing httpd, or working with an external component (a third party module, browser etc.) we ask you to start by bringing your question to the User Support and Discussion mailing list, see [https://httpd.apache.org/lists.html#http-users] for details. Include a link to this Bugzilla report for completeness with your question.

If your report was clearly a defect in httpd or a feature request, we ask that you retest using a modern httpd release (2.4.33 or later) released in the past year. If it can be reproduced, please reopen this bug and change the Version field above to the httpd version you have reconfirmed with.

Your help in identifying defects or enhancements still applicable to the current httpd server software release is greatly appreciated.