1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

fixed realloc not working correctly with M_GUARD

This commit is contained in:
Stefan Bellon 2001-12-22 18:47:58 +00:00
parent 97d3149e92
commit dc6d5b2a41
2 changed files with 22 additions and 13 deletions

View File

@ -1,3 +1,8 @@
2001-12-22 Stefan Bellon <sbellon@sbellon.de>
* memory.c (realloc): Fixed realloc not working when M_GUARD is
defined and first parameter is NULL.
2001-12-22 Timo Schulz <ts@winpt.org>
* fileutil.c (is_file_compressed): New.

View File

@ -475,23 +475,26 @@ FNAME(alloc_secure_clear)( size_t n FNAMEPRT)
void *
FNAME(realloc)( void *a, size_t n FNAMEPRT )
{
void *b;
#ifdef M_GUARD
unsigned char *p = a;
void *b;
size_t len = m_size(a);
if( a ) {
unsigned char *p = a;
size_t len = m_size(a);
if( len >= n ) /* we don't shrink for now */
return a;
if( p[-1] == MAGIC_SEC_BYTE )
b = FNAME(alloc_secure_clear)(n FNAMEARG);
if( len >= n ) /* we don't shrink for now */
return a;
if( p[-1] == MAGIC_SEC_BYTE )
b = FNAME(alloc_secure_clear)(n FNAMEARG);
else
b = FNAME(alloc_clear)(n FNAMEARG);
FNAME(check)(NULL FNAMEARG);
memcpy(b, a, len );
FNAME(free)(p FNAMEARG);
}
else
b = FNAME(alloc_clear)(n FNAMEARG);
FNAME(check)(NULL FNAMEARG);
memcpy(b, a, len );
FNAME(free)(p FNAMEARG);
b = FNAME(alloc)(n);
#else
void *b;
if( m_is_secure(a) ) {
if( !(b = secmem_realloc( a, n )) )
out_of_core(n,1);
@ -501,6 +504,7 @@ FNAME(realloc)( void *a, size_t n FNAMEPRT )
out_of_core(n,0);
}
#endif
return b;
}