secmem_realloc bug fix

Matt Kraai kraai at alumni.carnegiemellon.edu
Wed Aug 30 15:25:01 CEST 2000


Howdy,

The code for secmem_realloc calls secmem_malloc but does not ensure that
the result isn't NULL.  The attached patch (against CVS) adds the check.

If I wrote code so that secmem_malloc could split blocks, secmem_realloc
could shrink them, and secmem_free could merge them, would you consider
including it?

Matt
-------------- next part --------------
--- secmem.c.orig	Wed Aug 30 14:03:17 2000
+++ secmem.c	Wed Aug 30 14:06:44 2000
@@ -344,10 +344,11 @@
     size = mb->size;
     if( newsize < size )
 	return p; /* it is easier not to shrink the memory */
-    a = secmem_malloc( newsize );
-    memcpy(a, p, size);
-    memset((char*)a+size, 0, newsize-size);
-    secmem_free(p);
+    if( (a = secmem_malloc( newsize )) != NULL ) {
+	memcpy(a, p, size);
+	memset((char*)a+size, 0, newsize-size);
+	secmem_free(p);
+    }
     return a;
 }
 


More information about the Gnupg-devel mailing list