System : OpenBSD 4.8
Details : OpenBSD 4.8-current (GENERIC.MP) #644: Sun Nov 21 11:19:23 MST 2010
deraadt@amd64.openbsd.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
Architecture: OpenBSD.amd64
A bug existed in mod_proxy when using httpd as as reverse proxy. httpd would send a
host-header with port 80 specified even though the request - from the client - was not specified
as hostname:80 (Bug report pr6009). The author of this report suggested a fix that was *not*
used. An alternative fix was applied.
Unfortunately this alternative fix causes a new problem: httpd sends back a host-header with the
cvs server: Diffing .
Index: proxy_http.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/proxy/proxy_http.c,v
retrieving revision 1.21
diff -u -r1.21 proxy_http.c
--- proxy_http.c 25 Feb 2010 07:53:07 -0000 1.21
+++ proxy_http.c 25 Nov 2010 10:02:31 -0000
@@ -367,7 +367,7 @@
AP_HOOK_DECLINE(DECLINED),
&rc, r, f, desthost, destportstr, destportstr);
if (rc == DECLINED) {
- if (destportstr != NULL && destport != DEFAULT_HTTP_PORT)
+ if (destportstr != NULL && atoi(destportstr) != destport)
ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF, NULL);
else
ap_bvputs(f, "Host: ", desthost, CRLF, NULL);
The above if-expression will always evaluate as false because destport != DEFAULT_HTTP_PORT
will always be evaluated as false. Reason hereof is that in line 118 of the code the variable
destport is set to DEFAULT_HTTP_PORT and never changes. What really has to be checked is the
value of destportstr in relation to destport (or DEFAULT_HTTP_PORT) - as describes in the
original fix from pr6009.
The above fix implements the same solution as the original fix using string->int conversion
instead of int->string conversion.
dmesg:
OpenBSD 4.8-current (GENERIC.MP) #644: Sun ...On Tue, Jan 4, 2011 at 12:11 PM, Jasper Lievisse Adriaanse
As requested by Jasper a new diff using strtonum().
Index: proxy_http.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/src/modules/proxy/proxy_http.c,v
retrieving revision 1.21
diff -u -r1.21 proxy_http.c
--- proxy_http.c 25 Feb 2010 07:53:07 -0000 1.21
+++ proxy_http.c 4 Jan 2011 13:33:23 -0000
@@ -169,6 +169,8 @@
int result, major, minor;
const char *content_length;
const char *peer;
+ int destportstrtonum;
+ const char *errstr;
void *sconf = r->server->module_config;
proxy_server_conf *conf =
@@ -367,7 +369,11 @@
AP_HOOK_DECLINE(DECLINED),
&rc, r, f, desthost, destportstr, destportstr);
if (rc == DECLINED) {
- if (destportstr != NULL && destport != DEFAULT_HTTP_PORT)
+ destportstrtonum = strtonum(destportstr, 0, 65535, &errstr);
+ if (errstr)
+ errx(1, "The destination port is %s: %s", errstr, destportstr);
+
+ if (destportstr != NULL && destportstrtonum != destport)
ap_bvputs(f, "Host: ", desthost, ":", destportstr, CRLF, NULL);
else
ap_bvputs(f, "Host: ", desthost, CRLF, NULL);
