aboutsummaryrefslogtreecommitdiffstats
path: root/common/membuf.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2006-08-01 12:23:34 +0000
committerWerner Koch <[email protected]>2006-08-01 12:23:34 +0000
commit8c219602515ae1dba5bc0da31077852dab61809e (patch)
tree49d596d702cfec2b8cc42ccaf8c90c82d5200ac5 /common/membuf.c
parentForgot this one. (diff)
parent2006-07-29 Marcus Brinkmann <[email protected]> (diff)
downloadgnupg-8c219602515ae1dba5bc0da31077852dab61809e.tar.gz
gnupg-8c219602515ae1dba5bc0da31077852dab61809e.zip
Moved 1.9 branch to trunk
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);