Hi David, On Fri, Dec 28, 2012 at 01:46:32AM +0100, David BERARD wrote: > Hi, > > I start to evaluate the new add-header/set-header option, I encountered > issues. > I use nginx as web server behind HAProxy, and nginx reply 400 bad > request at every request. > > The header set with add-header/set-header is malformed, I have a null > character before the end of the > line, for exemple : > > http-request set-header X-SSL-TOTO %[ssl_fc] > > set the following header : X-SSL-TOTO: 1\000\r\n > > The length of header value seem too big, the following workaround fix > this issue (not optimal I now):
OK I see what's happening. I'd rather fix the root cause of this issue, it's build_logline() which returns an ambiguous length. Could you please try the attached patch instead ? It works for me right here. Thanks, Willy
>From df97447088ec931320fca6370cc360cb19a82a59 Mon Sep 17 00:00:00 2001 From: Willy Tarreau <[email protected]> Date: Fri, 28 Dec 2012 02:44:01 +0100 Subject: 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. --- src/log.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 @@ 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; } } -- 1.7.12.2.21.g234cd45.dirty

