]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: http: http-request add-header emits a corrupted header
authorWilly Tarreau <w@1wt.eu>
Fri, 28 Dec 2012 01:44:01 +0000 (02:44 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 28 Dec 2012 01:46:36 +0000 (02:46 +0100)
David BERARD reported that http-request add-header passes a \0 along
with the header field, which of course is not appropriate. This is
caused by build_logline() which sometimes returns the size with the
trailing zero and sometimes can return an empty string. Let's fix
this function instead of fixing the places where it's used.

src/log.c

index c07b62d6b5bddbd7e62487e9b3866c1dee56bfe9..b733811d3f0e62ef765815d0274f80992aaddaa8 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -844,7 +844,11 @@ const char sess_set_cookie[8] = "NPDIRU67";        /* No set-cookie, Set-cookie found a
                } while(0)
 
 
-
+/* Builds a log line in <dst> based on <list_format>, and stops before reaching
+ * <maxsize> characters. Returns the size of the output string in characters,
+ * not counting the trailing zero which is always added if the resulting size
+ * is not zero.
+ */
 int build_logline(struct session *s, char *dst, size_t maxsize, struct list *list_format)
 {
        struct proxy *fe = s->fe;
@@ -1474,8 +1478,7 @@ int build_logline(struct session *s, char *dst, size_t maxsize, struct list *lis
 out:
        /* *tmplog is a unused character */
        *tmplog = '\0';
-
-       return tmplog - dst + 1;
+       return tmplog - dst;
 
 }
 
@@ -1507,7 +1510,7 @@ void sess_log(struct session *s)
        size = tmplog - logline;
        size += build_logline(s, tmplog, sizeof(logline) - size, &s->fe->logformat);
        if (size > 0) {
-               __send_log(s->fe, level, logline, size);
+               __send_log(s->fe, level, logline, size + 1);
                s->logs.logwait = 0;
        }
 }