out of memory while allocating 0 bytes

Werner Koch wk at gnupg.org
Sun Sep 15 12:39:02 CEST 2002


On Sun, 15 Sep 2002 03:13:41 +0900 (JST), Yamagata Yoriyuki said:

> when m_alloc is called with the argument n = 0.  Since malloc in this
> system returns NULL for the request of 0-byte allocation, this causes

This is known.  The quick fix is to change it in util/memory.c:

void *
FNAME(alloc)( size_t n FNAMEPRT )
...
  #else
    /* mallocing zero bytes is undefined by ISO-C, so we better make
       sure that it won't happen */
    if (!n)
      n = 1;
    if( !(p = malloc( n )) )
	out_of_core(n,0);
    return p;

similar for the other allocation functions.

> I am able to compile with --enable-m-guard configure option, but I
> don't think this is the supposed use of the option.  Does GnuPG 1.2
> fix the problem?

Yes it is fixed. 


Shalom-Salam,

   Werner





More information about the Gnupg-devel mailing list