]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] http: take a capture of bad content-lengths.
authorWilly Tarreau <w@1wt.eu>
Fri, 2 Sep 2011 18:33:27 +0000 (20:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 4 Sep 2011 22:54:57 +0000 (00:54 +0200)
Sometimes a bad content-length header is encountered and this causes
an abort. It's hard to debug without a trace, so let's take a capture
of the contents when this happens.

src/proto_http.c

index 439e1cee09375d2fbb627da0402cfdd1e3cc2654..26b8f73ca9a970778a27ee191b72c11a19bd4639 100644 (file)
@@ -2808,17 +2808,25 @@ int http_wait_for_request(struct session *s, struct buffer *req, int an_bit)
               http_find_header2("Content-Length", 14, msg->sol, &txn->hdr_idx, &ctx)) {
                signed long long cl;
 
-               if (!ctx.vlen)
+               if (!ctx.vlen) {
+                       msg->err_pos = ctx.line + ctx.val - req->data;
                        goto return_bad_req;
+               }
 
-               if (strl2llrc(ctx.line + ctx.val, ctx.vlen, &cl))
+               if (strl2llrc(ctx.line + ctx.val, ctx.vlen, &cl)) {
+                       msg->err_pos = ctx.line + ctx.val - req->data;
                        goto return_bad_req; /* parse failure */
+               }
 
-               if (cl < 0)
+               if (cl < 0) {
+                       msg->err_pos = ctx.line + ctx.val - req->data;
                        goto return_bad_req;
+               }
 
-               if ((txn->flags & TX_REQ_CNT_LEN) && (msg->chunk_len != cl))
+               if ((txn->flags & TX_REQ_CNT_LEN) && (msg->chunk_len != cl)) {
+                       msg->err_pos = ctx.line + ctx.val - req->data;
                        goto return_bad_req; /* already specified, was different */
+               }
 
                txn->flags |= TX_REQ_CNT_LEN | TX_REQ_XFER_LEN;
                msg->body_len = msg->chunk_len = cl;
@@ -5023,17 +5031,25 @@ int http_wait_for_response(struct session *s, struct buffer *rep, int an_bit)
               http_find_header2("Content-Length", 14, msg->sol, &txn->hdr_idx, &ctx)) {
                signed long long cl;
 
-               if (!ctx.vlen)
+               if (!ctx.vlen) {
+                       msg->err_pos = ctx.line + ctx.val - rep->data;
                        goto hdr_response_bad;
+               }
 
-               if (strl2llrc(ctx.line + ctx.val, ctx.vlen, &cl))
+               if (strl2llrc(ctx.line + ctx.val, ctx.vlen, &cl)) {
+                       msg->err_pos = ctx.line + ctx.val - rep->data;
                        goto hdr_response_bad; /* parse failure */
+               }
 
-               if (cl < 0)
+               if (cl < 0) {
+                       msg->err_pos = ctx.line + ctx.val - rep->data;
                        goto hdr_response_bad;
+               }
 
-               if ((txn->flags & TX_RES_CNT_LEN) && (msg->chunk_len != cl))
+               if ((txn->flags & TX_RES_CNT_LEN) && (msg->chunk_len != cl)) {
+                       msg->err_pos = ctx.line + ctx.val - rep->data;
                        goto hdr_response_bad; /* already specified, was different */
+               }
 
                txn->flags |= TX_RES_CNT_LEN | TX_RES_XFER_LEN;
                msg->body_len = msg->chunk_len = cl;