From 9884df8c9e499f948cc40e09b78faa25b820e4ee Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 3 Jun 2015 11:07:56 -0600 Subject: [PATCH] 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. --- lib/util/snprintf.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 */ -- 2.40.0