Hello!
I'm using these changes for some time. Maybe they will be useful.
1. Set conn->transparent early after connection establishment and reset
connection on transparent connections when there is no valid request.
2. Check http->entry && http->entry->mem_obj && http->entry->mem_obj->reply
to avoid NULL pointer dereference (I had one quite some time ago).
3. create method object even for invalid requests (this fixes null pointer
dereferences in many other places).
--
Alexander.
Index: HttpReply.c
===================================================================
RCS file: /squid/squid/src/HttpReply.c,v
retrieving revision 1.68
diff -u -p -r1.68 HttpReply.c
--- HttpReply.c 15 Aug 2008 05:00:32 -0000 1.68
+++ HttpReply.c 3 Sep 2008 08:40:53 -0000
@@ -543,10 +543,9 @@ httpReplyBodySize(method_t * method, con
{
if (reply->sline.version.major < 1)
return -1;
- else if (method != NULL) {
- if (method->code == METHOD_HEAD)
- return 0;
- } else if (reply->sline.status == HTTP_OK)
+ if (method != NULL && method->code == METHOD_HEAD)
+ return 0;
+ else if (reply->sline.status == HTTP_OK)
(void) 0; /* common case, continue */
else if (reply->sline.status == HTTP_NO_CONTENT)
return 0;
Index: client_side.c
===================================================================
RCS file: /squid/squid/src/client_side.c,v
retrieving revision 1.788
diff -u -p -r1.788 client_side.c
--- client_side.c 29 Aug 2008 00:21:39 -0000 1.788
+++ client_side.c 8 Sep 2008 09:59:40 -0000
@@ -392,8 +392,11 @@ clientCreateStoreEntry(clientHttpRequest
* For erroneous requests, we might not have a h->request,
* so make a fake one.
*/
- if (h->request == NULL)
+ if (h->request == NULL) {
h->request = requestLink(requestCreate(m, PROTO_NONE, null_string));
+ if(h->conn && h->conn->transparent)
+ h->request->flags.reset_tcp = 1;
+ }
e = storeCreateEntry(h->uri, flags, m);
if (h->request->store_url)
storeEntrySetStoreUrl(e, h->request->store_url);
@@ -1698,7 +1701,8 @@ clientBuildRangeHeader(clientHttpRequest
range_err = "origin server does ranges";
else if (rep->content_length < 0)
range_err = "unknown length";
- else if (rep->content_length !=
http->entry->mem_obj->reply->content_length)
+ else if (http->entry && http->entry->mem_obj && http->entry->mem_obj->reply
+ && rep->content_length !=
http->entry->mem_obj->reply->content_length)
range_err = "INCONSISTENT length"; /* a bug? */
else if (httpHeaderHas(&http->request->header, HDR_IF_RANGE) &&
!clientIfRangeMatch(http, rep))
range_err = "If-Range match failed";
@@ -3807,10 +3811,15 @@ parseHttpRequest(ConnStateData * conn, H
*method_p = NULL;
*status = -1;
+ if (conn->port->transparent && clientNatLookup(conn) == 0)
+ conn->transparent = 1;
+
/* Parse the request line */
ret = httpMsgParseRequestLine(hmsg);
- if (ret == -1)
+ if (ret == -1) {
+ *method_p = urlMethodGetKnownByCode(METHOD_NONE);
return parseHttpRequestAbort(conn, "error:invalid-request");
+ }
if (ret == 0) {
debug(33, 5) ("Incomplete request, waiting for end of request line\n");
*status = 0;
@@ -3833,6 +3842,7 @@ parseHttpRequest(ConnStateData * conn, H
/* Enforce max_request_size */
if (req_sz >= Config.maxRequestHeaderSize) {
debug(33, 5) ("parseHttpRequest: Too large request\n");
+ *method_p = urlMethodGetKnownByCode(METHOD_NONE);
return parseHttpRequestAbort(conn, "error:request-too-large");
}
/* Wrap the request method */
@@ -3924,8 +3934,6 @@ parseHttpRequest(ConnStateData * conn, H
}
#endif
}
- if (conn->port->transparent && clientNatLookup(conn) == 0)
- conn->transparent = 1;
if (!host && conn->transparent) {
port = ntohs(conn->me.sin_port);
if (!host)