mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
[MEDIUM] ensure we never overflow in chunk_printf()
The result of the vsnprintf() called in chunk_printf() must be checked, and should be added only if lower than the requested size. We simply return zero if we cannot write the chunk.
This commit is contained in:
parent
ca769dc631
commit
dceaa0894b
@ -193,9 +193,15 @@ int buffer_insert_line2(struct buffer *b, char *pos, const char *str, int len)
|
|||||||
int chunk_printf(struct chunk *chk, int size, const char *fmt, ...)
|
int chunk_printf(struct chunk *chk, int size, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list argp;
|
va_list argp;
|
||||||
|
int ret;
|
||||||
|
|
||||||
va_start(argp, fmt);
|
va_start(argp, fmt);
|
||||||
chk->len += vsnprintf(chk->str + chk->len, size - chk->len, fmt, argp);
|
ret = vsnprintf(chk->str + chk->len, size - chk->len, fmt, argp);
|
||||||
|
if (ret >= size - chk->len)
|
||||||
|
/* do not copy anything in case of truncation */
|
||||||
|
chk->str[chk->len] = 0;
|
||||||
|
else
|
||||||
|
chk->len += ret;
|
||||||
va_end(argp);
|
va_end(argp);
|
||||||
return chk->len;
|
return chk->len;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user