From: Todd C. Miller Date: Wed, 3 Jun 2015 17:07:56 +0000 (-0600) Subject: If asprintf() or vasprintf() fail, set the dest pointer to NULL X-Git-Tag: SUDO_1_8_14^2~99 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9884df8c9e499f948cc40e09b78faa25b820e4ee;p=sudo If asprintf() or vasprintf() fail, set the dest pointer to NULL like BSD and Solaris do. This appears to be the direction glibc is going as well. --- diff --git a/lib/util/snprintf.c b/lib/util/snprintf.c index 25b53e689..b980d3dc7 100644 --- a/lib/util/snprintf.c +++ b/lib/util/snprintf.c @@ -1566,8 +1566,12 @@ sudo_snprintf(char *str, size_t n, char const *fmt, ...) int sudo_vasprintf(char **str, const char *fmt, va_list ap) { + int ret; - return xxxprintf(str, 0, 1, fmt, ap); + ret = xxxprintf(str, 0, 1, fmt, ap); + if (ret == -1) + *str = NULL; + return ret; } #endif /* !HAVE_VASPRINTF || PREFER_PORTABLE_SNPRINTF */ @@ -1581,6 +1585,8 @@ sudo_asprintf(char **str, char const *fmt, ...) va_start(ap, fmt); ret = xxxprintf(str, 0, 1, fmt, ap); va_end(ap); + if (ret == -1) + *str = NULL; return ret; } #endif /* !HAVE_ASPRINTF || PREFER_PORTABLE_SNPRINTF */