diff options
Diffstat (limited to '')
-rw-r--r-- | common/membuf.c (renamed from util/membuf.c) | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/util/membuf.c b/common/membuf.c index 44347fa1b..2d35fefab 100644 --- a/util/membuf.c +++ b/common/membuf.c @@ -22,7 +22,8 @@ #include <config.h> #include <stdlib.h> #include <errno.h> -#include <string.h> + +#include "membuf.h" #include "util.h" @@ -39,7 +40,7 @@ init_membuf (membuf_t *mb, int initiallen) mb->len = 0; mb->size = initiallen; mb->out_of_core = 0; - mb->buf = xmalloc (initiallen); + mb->buf = xtrymalloc (initiallen); if (!mb->buf) mb->out_of_core = errno; } @@ -56,7 +57,17 @@ put_membuf (membuf_t *mb, const void *buf, size_t len) char *p; mb->size += len + 1024; - p = xrealloc (mb->buf, mb->size); + p = xtryrealloc (mb->buf, mb->size); + if (!p) + { + mb->out_of_core = errno; + /* Wipe out what we already accumulated. This is required + in case we are storing sensitive data here. The membuf + API does not provide another way to cleanup after an + error. */ + memset (mb->buf, 0, mb->len); + return; + } mb->buf = p; } memcpy (mb->buf + mb->len, buf, len); |