diff options
author | Werner Koch <[email protected]> | 2014-06-02 09:47:25 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2014-06-02 09:47:25 +0000 |
commit | 99972bd6e9abea71f270284f49997de5f00208af (patch) | |
tree | f935c5ff69d98be62d6794f06a3fea55342c05de /common/xmalloc.c | |
parent | dirmngr: Print certificates on failed TLS verification. (diff) | |
download | gnupg-99972bd6e9abea71f270284f49997de5f00208af.tar.gz gnupg-99972bd6e9abea71f270284f49997de5f00208af.zip |
gpg: Fix bug parsing a zero length user id.
* g10/getkey.c (get_user_id): Do not call xmalloc with 0.
* common/xmalloc.c (xmalloc, xcalloc): Take extra precaution not to
pass 0 to the arguments.
--
The problem did not occur in 1.x because over there the xmalloc makes
sure to allocate at least one byte. With 2.x for most calls the
xmalloc of Libgcrypt is used and Libgcrypt returns an error insteead
of silent allocating a byte. Thus gpg 2.x bailed out with an
"Fatal: out of core while allocating 0 bytes".
The extra code in xmalloc.c is for more robustness for the other
xmalloc calls.
Diffstat (limited to '')
-rw-r--r-- | common/xmalloc.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/common/xmalloc.c b/common/xmalloc.c index 999ec00f8..3378e487b 100644 --- a/common/xmalloc.c +++ b/common/xmalloc.c @@ -47,7 +47,15 @@ out_of_core(void) void * xmalloc( size_t n ) { - void *p = malloc( n ); + void *p; + + /* Make sure that xmalloc (0) works. This is the same behaviour + has in gpg 2.x. Note that in contrast to this code, Libgcrypt + (and thus most xmallocs in gpg 2.x) detect the !n and bail out. */ + if (!n) + n = 1; + + p = malloc( n ); if( !p ) out_of_core(); return p; @@ -65,7 +73,14 @@ xrealloc( void *a, size_t n ) void * xcalloc( size_t n, size_t m ) { - void *p = calloc( n, m ); + void *p; + + if (!n) + n = 1; + if (!m) + m = 1; + + p = calloc( n, m ); if( !p ) out_of_core(); return p; |