From be6db83462c0d4a7067ab303644440026c93d685 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Tue, 5 Dec 2006 22:58:09 +1100 Subject: - (djm) [bsd-asprintf.c] Better test for bad vsnprintf lengths; ok dtucker@ --- openbsd-compat/bsd-asprintf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'openbsd-compat/bsd-asprintf.c') diff --git a/openbsd-compat/bsd-asprintf.c b/openbsd-compat/bsd-asprintf.c index 67480139e..00fa0dfd8 100644 --- a/openbsd-compat/bsd-asprintf.c +++ b/openbsd-compat/bsd-asprintf.c @@ -39,7 +39,8 @@ #define INIT_SZ 128 -int vasprintf(char **str, const char *fmt, va_list ap) +int +vasprintf(char **str, const char *fmt, va_list ap) { int ret = -1; va_list ap2; @@ -53,7 +54,7 @@ int vasprintf(char **str, const char *fmt, va_list ap) ret = vsnprintf(string, INIT_SZ, fmt, ap2); if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */ *str = string; - } else if (ret == INT_MAX) { /* shouldn't happen */ + } else if (ret == INT_MAX || ret < 0) { /* Bad length */ goto fail; } else { /* bigger than initial, realloc allowing for nul */ len = (size_t)ret + 1; -- cgit v1.2.3