diff options
author | Werner Koch <wk@gnupg.org> | 2006-10-04 18:45:04 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2006-10-04 18:45:04 +0200 |
commit | 8684a78518691a9d033a8af2d743b8d2fa9d2351 (patch) | |
tree | 1e2ace515eb108ef7c191f008582cdd282d15ec2 /common/membuf.c | |
parent | Preparing a new release (diff) | |
download | gnupg2-8684a78518691a9d033a8af2d743b8d2fa9d2351.tar.xz gnupg2-8684a78518691a9d033a8af2d743b8d2fa9d2351.zip |
Fixed agent access for gpg.
Diffstat (limited to 'common/membuf.c')
-rw-r--r-- | common/membuf.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/common/membuf.c b/common/membuf.c index 2d35fefab..51014592b 100644 --- a/common/membuf.c +++ b/common/membuf.c @@ -42,7 +42,19 @@ init_membuf (membuf_t *mb, int initiallen) mb->out_of_core = 0; mb->buf = xtrymalloc (initiallen); if (!mb->buf) - mb->out_of_core = errno; + mb->out_of_core = errno; +} + +/* Same as init_membuf but allocates the buffer in secure memory. */ +void +init_membuf_secure (membuf_t *mb, int initiallen) +{ + mb->len = 0; + mb->size = initiallen; + mb->out_of_core = 0; + mb->buf = xtrymalloc (initiallen); + if (!mb->buf) + mb->out_of_core = errno; } @@ -60,7 +72,7 @@ put_membuf (membuf_t *mb, const void *buf, size_t len) p = xtryrealloc (mb->buf, mb->size); if (!p) { - mb->out_of_core = errno; + mb->out_of_core = errno ? errno : ENOMEM; /* 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 @@ -84,11 +96,13 @@ get_membuf (membuf_t *mb, size_t *len) { xfree (mb->buf); mb->buf = NULL; + errno = mb->out_of_core; return NULL; } p = mb->buf; - *len = mb->len; + if (len) + *len = mb->len; mb->buf = NULL; mb->out_of_core = ENOMEM; /* hack to make sure it won't get reused. */ return p; |