BUG/MINOR: http: http-request add-header emits a corrupted header
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.
diff --git a/src/log.c b/src/log.c
index c07b62d..b733811 100644
--- a/src/log.c
+++ b/src/log.c
@@ -844,7 +844,11 @@
} 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 @@
out:
/* *tmplog is a unused character */
*tmplog = '\0';
-
- return tmplog - dst + 1;
+ return tmplog - dst;
}
@@ -1507,7 +1510,7 @@
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;
}
}