]> andersk Git - gssapi-openssh.git/blobdiff - openssh/openbsd-compat/bsd-asprintf.c
Import of OpenSSH 4.9p1
[gssapi-openssh.git] / openssh / openbsd-compat / bsd-asprintf.c
index 5ca01f80f3d9cad5a30d7a3df732285216a1a1d6..3368195d443ae1a8470528ecf0211ccdfba17847 100644 (file)
 
 #ifndef HAVE_VASPRINTF
 
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
 #ifndef VA_COPY
 # ifdef HAVE_VA_COPY
 #  define VA_COPY(dest, src) va_copy(dest, src)
@@ -35,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;
@@ -49,7 +54,8 @@ 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 */
+               free(string);
                goto fail;
        } else {        /* bigger than initial, realloc allowing for nul */
                len = (size_t)ret + 1;
This page took 0.855692 seconds and 4 git commands to generate.