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é
diff -Naur haproxy-1.4.1/src/proto_http.c haproxy-1.4.1-clf/src/proto_http.c
--- haproxy-1.4.1/src/proto_http.c	2010-03-04 23:39:19.000000000 +0100
+++ haproxy-1.4.1-clf/src/proto_http.c	2010-03-13 15:02:36.000000000 +0100
@@ -1018,11 +1018,16 @@
 		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 @@
 		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;
+			}
 		}
 	}

Reply via email to