]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[BUG] clf logs segfault when capturing a non existant header
authorCyril Bonté <cyril.bonte@free.fr>
Sat, 13 Mar 2010 14:15:07 +0000 (15:15 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 14 Mar 2010 19:02:10 +0000 (20:02 +0100)
Hi Willy,

Please find a small patch to prevent haproxy segfaulting when logging captured headers in CLF format.

Example config to reproduce the bug :
listen test :10080
log 127.0.0.1 local7 debug err
mode http
option httplog clf
capture request header NonExistantHeader len 16

--
Cyril Bonté

src/proto_http.c

index fea3d362e60d05346abae95899c10249997bd737..ad44a2edbc5be7d984b28c45d0a25410e13661a6 100644 (file)
@@ -1018,11 +1018,16 @@ void http_sess_clflog(struct session *s)
                for (hdr = 0; hdr < fe->nb_req_cap; hdr++) {
                        if (h >= sizeof (tmpline) + tmpline - 4)
                                goto trunc;
-                       *(h++) = ' ';
-                       *(h++) = '\"';
-                       h = encode_string(h, tmpline + sizeof(tmpline) - 2,
-                                         '#', hdr_encode_map, txn->req.cap[hdr]);
-                       *(h++) = '\"';
+                       if (txn->req.cap[hdr] != NULL) {
+                               *(h++) = ' ';
+                               *(h++) = '\"';
+                               h = encode_string(h, tmpline + sizeof(tmpline) - 2,
+                                               '#', hdr_encode_map, txn->req.cap[hdr]);
+                               *(h++) = '\"';
+                       } else {
+                               memcpy(h, " \"-\"", 4);
+                               h += 4;
+                       }
                }
        }
 
@@ -1030,11 +1035,16 @@ void http_sess_clflog(struct session *s)
                for (hdr = 0; hdr < fe->nb_rsp_cap; hdr++) {
                        if (h >= sizeof (tmpline) + tmpline - 4)
                                goto trunc;
-                       *(h++) = ' ';
-                       *(h++) = '\"';
-                       h = encode_string(h, tmpline + sizeof(tmpline) - 2,
-                                         '#', hdr_encode_map, txn->rsp.cap[hdr]);
-                       *(h++) = '\"';
+                       if (txn->rsp.cap[hdr] != NULL) {
+                               *(h++) = ' ';
+                               *(h++) = '\"';
+                               h = encode_string(h, tmpline + sizeof(tmpline) - 2,
+                                               '#', hdr_encode_map, txn->rsp.cap[hdr]);
+                               *(h++) = '\"';
+                       } else {
+                               memcpy(h, " \"-\"", 4);
+                               h += 4;
+                       }
                }
        }