summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/talloc/talloc.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/source4/lib/talloc/talloc.c b/source4/lib/talloc/talloc.c
index ac2fedebdc..6b3328420d 100644
--- a/source4/lib/talloc/talloc.c
+++ b/source4/lib/talloc/talloc.c
@@ -1011,7 +1011,9 @@ char *talloc_vasprintf(const void *t, const char *fmt, va_list ap)
VA_COPY(ap2, ap);
- len = vsnprintf(NULL, 0, fmt, ap2);
+ if ((len = vsnprintf(NULL, 0, fmt, ap2)) <= 0) {
+ return NULL;
+ }
ret = _talloc(t, len+1);
if (ret) {
@@ -1060,7 +1062,15 @@ char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap)
VA_COPY(ap2, ap);
s_len = tc->size - 1;
- len = vsnprintf(NULL, 0, fmt, ap2);
+ if ((len = vsnprintf(NULL, 0, fmt, ap2)) <= 0) {
+ /* Either the vsnprintf failed or the format resulted in
+ * no characters being formatted. In the former case, we
+ * ought to return NULL, in the latter we ought to return
+ * the original string. Most current callers of this
+ * function expect it to never return NULL.
+ */
+ return s;
+ }
s = talloc_realloc(NULL, s, char, s_len + len+1);
if (!s) return NULL;