Fix buffer overflow

Signed-off-by: Ian Stakenvicius <axs@gentoo.org>
This commit is contained in:
klondike 2013-04-01 21:07:57 +02:00 committed by Ian Stakenvicius
parent d8d626c7df
commit 50758bdd96

View File

@ -337,13 +337,15 @@ size_t util_strpcpyf(char **dest, size_t size, const char *src, ...)
va_list va; va_list va;
int i; int i;
if (!size) return 0; /*Nothing to do if size is 0*/
va_start(va, src); va_start(va, src);
i = vsnprintf(*dest, size, src, va); i = vsnprintf(*dest, size, src, va);
if (i < (int)size) { if (i < (int)size) {
*dest += i; *dest += i;
size -= i; size -= i;
} else { } else {
*dest += size; *dest += size - 1;
size = 0; size = 0;
} }
va_end(va); va_end(va);