mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
See ChangeLog: Fri Nov 19 17:15:20 CET 1999 Werner Koch
This commit is contained in:
parent
37f3c09edb
commit
2694bceb45
35 changed files with 422 additions and 289 deletions
|
@ -1,3 +1,24 @@
|
|||
Fri Nov 19 17:15:20 CET 1999 Werner Koch <wk@gnupg.de>
|
||||
|
||||
* argparse.c (default_strusage): Renamed to strusage. Fall back
|
||||
to the old behaviour if no sepcial strhandler has been set.
|
||||
|
||||
* memory.c (g10_private_check_heap): New.
|
||||
|
||||
* secmem.c (m_is_secure): Renamed to ...
|
||||
(g10_private_is_secure): ... this.
|
||||
* memory.c (g10_private_malloc): New. Takes core functionalty of ...
|
||||
(m_alloc): ... and calls it.
|
||||
(g10_private_malloc_secure): New. Takes core functionalty of ...
|
||||
(m_alloc_secure): ... and calls it.
|
||||
(g10_private_realloc): New. Takes core functionalty of ...
|
||||
(m_realloc): ... and this one calls it.
|
||||
(g10_private_free): Wraps around m_free().
|
||||
|
||||
* argparse.c (g10_set_strusage): New.
|
||||
(default_strusage): renamed to ...
|
||||
(g10_default_strusage): .. this.
|
||||
|
||||
Sat Nov 13 17:44:23 CET 1999 Werner Koch <wk@gnupg.de>
|
||||
|
||||
* g10u.c: Removed.
|
||||
|
|
|
@ -135,10 +135,13 @@ struct alias_def_s {
|
|||
const char *value; /* ptr into name */
|
||||
};
|
||||
|
||||
static const char *(*strusage_handler)( int ) = NULL;
|
||||
|
||||
static int set_opt_arg(ARGPARSE_ARGS *arg, unsigned flags, char *s);
|
||||
static void show_help(ARGPARSE_OPTS *opts, unsigned flags);
|
||||
static void show_version(void);
|
||||
|
||||
|
||||
static void
|
||||
initialize( ARGPARSE_ARGS *arg, const char *filename, unsigned *lineno )
|
||||
{
|
||||
|
@ -886,9 +889,13 @@ usage( int level )
|
|||
* 41: long usage note (with LF)
|
||||
*/
|
||||
const char *
|
||||
default_strusage( int level )
|
||||
strusage( int level )
|
||||
{
|
||||
const char *p = NULL;
|
||||
const char *p = strusage_handler? strusage_handler(level) : NULL;
|
||||
|
||||
if( p )
|
||||
return p;
|
||||
|
||||
switch( level ) {
|
||||
case 11: p = "foo"; break;
|
||||
case 13: p = "0.0"; break;
|
||||
|
@ -917,6 +924,11 @@ default_strusage( int level )
|
|||
return p;
|
||||
}
|
||||
|
||||
void
|
||||
set_strusage( const char *(*f)( int ) )
|
||||
{
|
||||
strusage_handler = f;
|
||||
}
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
|
|
118
util/memory.c
118
util/memory.c
|
@ -37,6 +37,9 @@
|
|||
#include "memory.h"
|
||||
#include "util.h"
|
||||
|
||||
/* FXIME: ugly hack. Need a prototype here bug can't include g10lib.h */
|
||||
int g10_private_is_secure( void *p );
|
||||
|
||||
|
||||
#define MAGIC_NOR_BYTE 0x55
|
||||
#define MAGIC_SEC_BYTE 0xcc
|
||||
|
@ -384,26 +387,60 @@ out_of_core(size_t n, int secure)
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************
|
||||
* Allocate memory of size n.
|
||||
* Return NULL if we are out of memory.
|
||||
*/
|
||||
void *
|
||||
g10_private_malloc( size_t n)
|
||||
{
|
||||
char *p;
|
||||
|
||||
#ifdef M_GUARD
|
||||
if( !(p = malloc( n + EXTRA_ALIGN+5 )) )
|
||||
return NULL;
|
||||
store_len(p,n,0);
|
||||
used_memory += n;
|
||||
p[4+EXTRA_ALIGN+n] = MAGIC_END_BYTE;
|
||||
return p+EXTRA_ALIGN+4;
|
||||
#else /* fixme: This can be done with a macro */
|
||||
return malloc( n );
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************
|
||||
* Allocate memory of size n.
|
||||
* This function gives up if we do not have enough memory
|
||||
*/
|
||||
void *
|
||||
FNAME(alloc)( size_t n FNAMEPRT )
|
||||
{
|
||||
char *p = g10_private_malloc( n );
|
||||
if( !p )
|
||||
out_of_core(n,0);
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
/****************
|
||||
* Allocate memory of size n from the secure memory pool.
|
||||
* Return NULL if we are out of memory.
|
||||
*/
|
||||
void *
|
||||
g10_private_malloc_secure( size_t n)
|
||||
{
|
||||
char *p;
|
||||
|
||||
#ifdef M_GUARD
|
||||
if( !(p = malloc( n + EXTRA_ALIGN+5 )) )
|
||||
out_of_core(n,0);
|
||||
store_len(p,n,0);
|
||||
used_memory += n;
|
||||
if( !(p = secmem_malloc( n +EXTRA_ALIGN+ 5 )) )
|
||||
return NULL;
|
||||
store_len(p,n,1);
|
||||
p[4+EXTRA_ALIGN+n] = MAGIC_END_BYTE;
|
||||
return p+EXTRA_ALIGN+4;
|
||||
#else
|
||||
if( !(p = malloc( n )) )
|
||||
out_of_core(n,0);
|
||||
return p;
|
||||
return secmem_malloc( n );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -414,19 +451,10 @@ FNAME(alloc)( size_t n FNAMEPRT )
|
|||
void *
|
||||
FNAME(alloc_secure)( size_t n FNAMEPRT )
|
||||
{
|
||||
char *p;
|
||||
|
||||
#ifdef M_GUARD
|
||||
if( !(p = secmem_malloc( n +EXTRA_ALIGN+ 5 )) )
|
||||
out_of_core(n,1);
|
||||
store_len(p,n,1);
|
||||
p[4+EXTRA_ALIGN+n] = MAGIC_END_BYTE;
|
||||
return p+EXTRA_ALIGN+4;
|
||||
#else
|
||||
if( !(p = secmem_malloc( n )) )
|
||||
char *p = g10_private_malloc_secure( n );
|
||||
if( !p )
|
||||
out_of_core(n,1);
|
||||
return p;
|
||||
#endif
|
||||
}
|
||||
|
||||
void *
|
||||
|
@ -447,12 +475,12 @@ FNAME(alloc_secure_clear)( size_t n FNAMEPRT)
|
|||
return p;
|
||||
}
|
||||
|
||||
|
||||
/****************
|
||||
* realloc and clear the old space
|
||||
* Return NULL if there is not enoug memory.
|
||||
*/
|
||||
void *
|
||||
FNAME(realloc)( void *a, size_t n FNAMEPRT )
|
||||
g10_private_realloc( void *a, size_t n )
|
||||
{
|
||||
#ifdef M_GUARD
|
||||
unsigned char *p = a;
|
||||
|
@ -462,28 +490,39 @@ FNAME(realloc)( void *a, size_t n FNAMEPRT )
|
|||
if( len >= n ) /* we don't shrink for now */
|
||||
return a;
|
||||
if( p[-1] == MAGIC_SEC_BYTE )
|
||||
b = FNAME(alloc_secure_clear)(n FNAMEARG);
|
||||
b = g10_private_malloc_secure(n);
|
||||
else
|
||||
b = FNAME(alloc_clear)(n FNAMEARG);
|
||||
b = g10_private_malloc(n);
|
||||
if( !b )
|
||||
return NULL;
|
||||
memset(p, 0, n );
|
||||
FNAME(check)(NULL FNAMEARG);
|
||||
memcpy(b, a, len );
|
||||
FNAME(free)(p FNAMEARG);
|
||||
return b;
|
||||
#else
|
||||
void *b;
|
||||
|
||||
if( m_is_secure(a) ) {
|
||||
if( !(b = secmem_realloc( a, n )) )
|
||||
out_of_core(n,1);
|
||||
if( g10_private_is_secure(a) ) {
|
||||
return secmem_realloc( a, n );
|
||||
}
|
||||
else {
|
||||
if( !(b = realloc( a, n )) )
|
||||
out_of_core(n,0);
|
||||
return realloc( a, n );
|
||||
}
|
||||
#endif
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
/****************
|
||||
* realloc and clear the old space
|
||||
*/
|
||||
void *
|
||||
FNAME(realloc)( void *a, size_t n FNAMEPRT )
|
||||
{
|
||||
void *b = g10_private_realloc( a, n );
|
||||
if( !b )
|
||||
out_of_core(n, g10_private_is_secure(a));
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
/****************
|
||||
* Free a pointer
|
||||
|
@ -499,20 +538,25 @@ FNAME(free)( void *a FNAMEPRT )
|
|||
free_entry(p-EXTRA_ALIGN-4, info);
|
||||
#elif M_GUARD
|
||||
m_check(p);
|
||||
if( m_is_secure(a) )
|
||||
if( g10_private_is_secure(a) )
|
||||
secmem_free(p-EXTRA_ALIGN-4);
|
||||
else {
|
||||
used_memory -= m_size(a);
|
||||
free(p-EXTRA_ALIGN-4);
|
||||
}
|
||||
#else
|
||||
if( m_is_secure(a) )
|
||||
if( g10_private_is_secure(a) )
|
||||
secmem_free(p);
|
||||
else
|
||||
free(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
g10_private_free( void *a )
|
||||
{
|
||||
m_free(a);
|
||||
}
|
||||
|
||||
void
|
||||
FNAME(check)( const void *a FNAMEPRT )
|
||||
|
@ -537,6 +581,13 @@ FNAME(check)( const void *a FNAMEPRT )
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
g10_private_check_heap( const void *p )
|
||||
{
|
||||
m_check(p);
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
m_size( const void *a )
|
||||
{
|
||||
|
@ -573,7 +624,7 @@ FNAME(copy)( const void *a FNAMEPRT )
|
|||
return NULL;
|
||||
|
||||
n = m_size(a); Aiiiih woher nehmen
|
||||
if( m_is_secure(a) )
|
||||
if( g10_private_is_secure(a) )
|
||||
b = FNAME(alloc_secure)(n FNAMEARG);
|
||||
else
|
||||
b = FNAME(alloc)(n FNAMEARG);
|
||||
|
@ -591,3 +642,4 @@ FNAME(strdup)( const char *a FNAMEPRT )
|
|||
return p;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -370,8 +370,9 @@ secmem_free( void *a )
|
|||
cur_alloced -= size;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
m_is_secure( const void *p )
|
||||
g10_private_is_secure( const void *p )
|
||||
{
|
||||
return p >= pool && p < (void*)((char*)pool+poolsize);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue