Missing variable initialization

[email protected] Thu, 8 Nov 2007 22:25:10 +0100
Newsgroups gmane.comp.web.fnord
Organization [ t]ivano Software GmbH
Message-ID <[email protected]>
--Boundary-00=_463MHKoGA3fenMZ
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi,

the attached patch fixes two problems:

1. the "args" variable is not reset to NULL after request processing,
   which can be a problem in keep-alive connections

2. a host-based redirect appends the request path to the redirect target
   but not the query string (if present)

The problems can be verified using these statements:

$ ln -s http://some-host.de/path/ test2:80
$ (echo "GET /hello/world.txt?foo=3Dbar HTTP/1.0"; echo "Host: test2"; echo=
=20
""; ) | ./fnord-cgi 2>/dev/null
HTTP/1.0 301 Go Away
Connection: close
Location: http://some-host.de/path/hello/world.txt

$ #                                               ^^^ missing ?foo=3Dbar
$ mkdir -p test\:80/really/long/path
$ touch test\:80/really/long/path/test.txt
$ (echo '#!/bin/sh'; echo "echo Content-type: text/plain"; echo "echo ''";=
=20
echo "/usr/bin/env") > test:80/test.cgi
$ chmod 755 test\:80/test.cgi
$ (echo "GET /really/long/path/test.txt?foo=3Dbar HTTP/1.0"; echo "Host: te=
st";=20
echo "Connection: keep-alive"; echo ""; sleep 2; echo "GET /test.cgi=20
HTTP/1.0"; echo "Host: test"; echo ""; ) |env -  ./fnord-cgi 2>/dev/null
HTTP/1.0 200 OK
Server: fnord/1.10
Content-Type: text/plain
Connection: Keep-Alive
Content-Length: 0
Last-Modified: Thu, 08 Nov 2007 21:21:08 GMT

HTTP/1.0 200 OK
Server: fnord/1.10
Pragma: no-cache
Connection: close
Content-type: text/plain

HTTP_USER_AGENT=3D?
SERVER_PORT=3D80
REQUEST_URI=3D/test.cgi
SCRIPT_NAME=3D/test.cgi
PWD=3D/tmp/fnord-1.10/test:80
HTTP_REFERER=3Dnone
SHLVL=3D1
SERVER_NAME=3Dtest:80
SERVER_SOFTWARE=3Dfnord/1.10
QUERY_STRING=3Dst
GATEWAY_INTERFACE=3DCGI/1.1
SERVER_PROTOCOL=3DHTTP/1.0
REQUEST_METHOD=3DGET
_=3D/usr/bin/env
$ # QUERY_STRING should be empty

Bye,
	Peter
=2D-=20
Peter Conrad      | The test of a first-rate intelligence is the ability to
Alicestra=DFe 102   | hold two opposed ideas in the mind at the same time, =
and=20
63263 Neu-Isenburg| still retain the ability to function.
Germany           |                        F. Scott Fitzgerald (1896 - 1940)

  email: [email protected] / WWW: http://www.unix-ag.uni-kl.de/~conr=
ad

--Boundary-00=_463MHKoGA3fenMZ
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="fnord-args.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="fnord-args.patch"

--- fnord-upstream-1.10/httpd.c	2007-04-18 18:43:46.000000000 +0200
+++ fnord-args/httpd.c	2007-11-08 20:34:56.000000000 +0100
@@ -1331,6 +1331,7 @@
     /* demangle path in-place */
     {
       register char *tmp,*d;
+      args=NULL;
       for (tmp=d=url; *tmp; ++tmp) {
 	if (*tmp=='?') { args=tmp+1; break; }
 	if (*tmp==' ') break;
@@ -1445,6 +1446,10 @@
 	  buffer_put(buffer_1,symlink,linklen);
 	  while (url[0]=='/') ++url;
 	  buffer_puts(buffer_1,url);
+	  if (args) {
+	    buffer_puts(buffer_1,"?");
+	    buffer_puts(buffer_1,args);
+	  }
 	}
 	retcode=301;
 	buffer_puts(buffer_1,"\r\n\r\n");

--Boundary-00=_463MHKoGA3fenMZ--