From: Nikos Mavrogiannopoulos Date: Wed, 22 May 2002 19:29:37 +0000 (+0000) Subject: Applied Jeff Johnson's patch which fixes type problems in 64 bit machines. Removed... X-Git-Tag: gnutls_0_4_3~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a5c46d2bda51cec16ede2fa50a82c6fac0c0d0be;p=thirdparty%2Fgnutls.git Applied Jeff Johnson's patch which fixes type problems in 64 bit machines. Removed the default allocation handlers, and made the libc's functions to be defaults. Added function which sets the memory allocation functions to be used. --- diff --git a/NEWS b/NEWS index 2154eeb33b..5565e17f8e 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +Version 0.4.3 +- The gnutls-extra library now compiles fine, if the opencdk library is + not present. +- Several bug fixes. +- Added gnutls_global_set_mem_func() function, to set the memory allocation + functions, if other than the defaults are to be used. +- The default memory allocation functions are now the ones in libc. + Version 0.4.2 (21/05/2002) - Separated ASN.1 structures parser documentation and TLS library documentation. diff --git a/THANKS b/THANKS index 8c0676dc90..ef4a6b8c1a 100644 --- a/THANKS +++ b/THANKS @@ -12,3 +12,4 @@ Mike Siers Marc Huber Guillaume Morin Andrew McDonald +Jeff Johnson diff --git a/acconfig.h b/acconfig.h index d343b67392..25a513c7f7 100644 --- a/acconfig.h +++ b/acconfig.h @@ -17,7 +17,6 @@ #undef LT_AGE #undef USE_DMALLOC #undef USE_EFENCE -#undef USE_LIBCALLOC #undef USE_GCRYPT #undef GNUTLS_VERSION diff --git a/configure.in b/configure.in index 72b68a8824..72d6c0adce 100644 --- a/configure.in +++ b/configure.in @@ -100,20 +100,18 @@ if test $ac_cv_c_compiler_gnu != no; then if test x$opt_maintainer_mode = xyes; then - CFLAGS="${CFLAGS} -O0 -ggdb3 -Wall -Wpointer-arith -Wstrict-prototypes" # -Werror + CFLAGS="${CFLAGS} -ggdb3 -Wall -Wpointer-arith -Wstrict-prototypes" # -Werror else - CFLAGS="${CFLAGS} -O2 -fexpensive-optimizations -fomit-frame-pointer" + CFLAGS="${CFLAGS} -O2 -finline-functions -fexpensive-optimizations -fomit-frame-pointer" fi if test x$opt_dmalloc_mode = xyes; then AC_CHECK_LIB( dmalloc, main) AC_DEFINE(USE_DMALLOC) - AC_DEFINE(USE_LIBCALLOC) else if test x$opt_efence_mode = xyes; then AC_CHECK_LIB( efence, main) AC_DEFINE(USE_EFENCE) - AC_DEFINE(USE_LIBCALLOC) fi fi @@ -308,7 +306,7 @@ AC_SUBST(LIBGNUTLS_EXTRA_CFLAGS) if test $ac_cv_c_compiler_gnu != no; then if test x$opt_profiler_mode = xyes; then - CFLAGS="${CFLAGS} -O0 `fc-config --cflags`" + CFLAGS="${CFLAGS} `fc-config --cflags`" AC_CHECK_PROG(FC_OK, fc-config, yes, no) if test x$FC_OK = xyes; then LIBS="$LIBS `fc-config --libs`" diff --git a/lib/auth_cert.c b/lib/auth_cert.c index b8934106fe..95a7b3aa14 100644 --- a/lib/auth_cert.c +++ b/lib/auth_cert.c @@ -330,7 +330,6 @@ static int _gnutls_find_acceptable_client_cert(GNUTLS_STATE state, if (indx == -1 && state->gnutls_internals.client_cert_callback != NULL && cred->ncerts > 0) { /* use a callback to get certificate */ gnutls_datum *my_certs = NULL; gnutls_datum *issuers_dn = NULL; - int count; int issuers_dn_len = 0; opaque* dataptr = data; int dataptr_size = data_size; @@ -388,8 +387,8 @@ static int _gnutls_find_acceptable_client_cert(GNUTLS_STATE state, data += 2; - issuers_dn[count].data = data; - issuers_dn[count].size = size; + issuers_dn[i].data = data; + issuers_dn[i].size = size; data += size; diff --git a/lib/gnutls.h.in.in b/lib/gnutls.h.in.in index 49960fdcf7..fef2943309 100644 --- a/lib/gnutls.h.in.in +++ b/lib/gnutls.h.in.in @@ -244,6 +244,14 @@ int gnutls_certificate_set_x509_key_mem(GNUTLS_CERTIFICATE_CREDENTIALS res, int gnutls_global_init(void); void gnutls_global_deinit(void); +void gnutls_global_set_mem_func( + void *(*gnutls_alloc_func)(size_t), void* (*gnutls_secure_alloc_func)(size_t), + int (*gnutls_is_secure_func)(const void*), void *(*gnutls_realloc_func)(void *, size_t), + void (*gnutls_free_func)(void*)); + +typedef void (*GNUTLS_LOG_FUNC)( const char*); +void gnutls_global_set_log_func( GNUTLS_LOG_FUNC log_func); + int gnutls_dh_params_set( GNUTLS_DH_PARAMS, gnutls_datum prime, gnutls_datum generator, int bits); int gnutls_dh_params_init( GNUTLS_DH_PARAMS*); void gnutls_dh_params_deinit( GNUTLS_DH_PARAMS); @@ -256,7 +264,6 @@ GNUTLS_TRANSPORT_PTR gnutls_transport_get_ptr(GNUTLS_STATE state); void gnutls_transport_set_lowat( GNUTLS_STATE state, int num); -typedef void (*GNUTLS_LOG_FUNC)( const char*); void gnutls_transport_set_push_func( GNUTLS_STATE, GNUTLS_PUSH_FUNC push_func); void gnutls_transport_set_pull_func( GNUTLS_STATE, GNUTLS_PULL_FUNC pull_func); diff --git a/lib/gnutls_algorithms.c b/lib/gnutls_algorithms.c index 9d3934ff2a..55102e324a 100644 --- a/lib/gnutls_algorithms.c +++ b/lib/gnutls_algorithms.c @@ -759,7 +759,7 @@ int _gnutls_version_is_supported(GNUTLS_STATE state, const GNUTLS_Version version) { -int ret; +int ret=0; GNUTLS_VERSION_ALG_LOOP(ret = p->supported); if (ret == 0) return 0; diff --git a/lib/gnutls_auth.c b/lib/gnutls_auth.c index 36fac45a8a..c6d4830c14 100644 --- a/lib/gnutls_auth.c +++ b/lib/gnutls_auth.c @@ -81,7 +81,7 @@ int gnutls_clear_creds( GNUTLS_STATE state) { * of a server. **/ int gnutls_cred_set( GNUTLS_STATE state, GNUTLS_CredType type, void* cred) { - AUTH_CRED * ccred, *pcred; + AUTH_CRED * ccred=NULL, *pcred=NULL; int exists=0; if (state->gnutls_key->cred==NULL) { /* begining of the list */ @@ -104,7 +104,9 @@ int gnutls_cred_set( GNUTLS_STATE state, GNUTLS_CredType type, void* cred) { pcred = ccred; ccred = ccred->next; } - + /* After this, pcred is not null. + */ + if (exists==0) { /* new entry */ pcred->next = gnutls_malloc(sizeof(AUTH_CRED)); if (pcred->next == NULL) return GNUTLS_E_MEMORY_ERROR; @@ -268,7 +270,7 @@ int _gnutls_auth_info_set( GNUTLS_STATE state, CredType type, int size, int allo * to passive eavesdropers. */ if ( gnutls_auth_get_type( state) != state->gnutls_key->auth_info_type) { - state->gnutls_key->auth_info = gnutls_realloc_fast( + state->gnutls_key->auth_info = gnutls_realloc( state->gnutls_key->auth_info, size); if (state->gnutls_key->auth_info == NULL) { gnutls_assert(); diff --git a/lib/gnutls_buffers.c b/lib/gnutls_buffers.c index 9144670e2a..8ffc26f8cb 100644 --- a/lib/gnutls_buffers.c +++ b/lib/gnutls_buffers.c @@ -159,9 +159,10 @@ int _gnutls_record_buffer_get(ContentType type, GNUTLS_STATE state, char *data, memmove(state->gnutls_internals.application_data_buffer.data, &state->gnutls_internals.application_data_buffer.data[length], state->gnutls_internals.application_data_buffer.size); + /* this does not fail */ state->gnutls_internals.application_data_buffer.data = - gnutls_realloc_fast(state->gnutls_internals.application_data_buffer.data, + gnutls_realloc(state->gnutls_internals.application_data_buffer.data, state->gnutls_internals.application_data_buffer.size); break; @@ -182,7 +183,7 @@ int _gnutls_record_buffer_get(ContentType type, GNUTLS_STATE state, char *data, /* does not fail */ state->gnutls_internals.handshake_data_buffer.data = - gnutls_realloc_fast(state->gnutls_internals.handshake_data_buffer.data, + gnutls_realloc(state->gnutls_internals.handshake_data_buffer.data, state->gnutls_internals.handshake_data_buffer.size); break; default: @@ -327,7 +328,7 @@ ssize_t _gnutls_io_read_buffered( GNUTLS_STATE state, opaque **iptr, size_t size int min, buf_pos; char *buf; int recvlowat = RCVLOWAT; - int recvdata; + int recvdata, alloc_size; *iptr = state->gnutls_internals.record_recv_buffer.data; @@ -366,9 +367,11 @@ ssize_t _gnutls_io_read_buffered( GNUTLS_STATE state, opaque **iptr, size_t size /* Allocate the data required to store the new packet. */ - state->gnutls_internals.record_recv_buffer.data = gnutls_realloc_fast( - state->gnutls_internals.record_recv_buffer.data, recvdata+state->gnutls_internals.record_recv_buffer.size); - if ( state->gnutls_internals.record_recv_buffer.data==NULL) { + + alloc_size = recvdata+state->gnutls_internals.record_recv_buffer.size; + state->gnutls_internals.record_recv_buffer.data = gnutls_realloc( + state->gnutls_internals.record_recv_buffer.data, alloc_size); + if ( state->gnutls_internals.record_recv_buffer.data==NULL && alloc_size > 0) { gnutls_assert(); return GNUTLS_E_MEMORY_ERROR; } @@ -481,10 +484,10 @@ static int _gnutls_buffer_insert( gnutls_datum * buffer, const opaque* _data, in } - buffer->data = gnutls_realloc_fast( buffer->data, data_size); + buffer->data = gnutls_realloc( buffer->data, data_size); buffer->size = data_size; - if (buffer->data == NULL) { + if (buffer->data == NULL && data_size > 0) { gnutls_assert(); return GNUTLS_E_MEMORY_ERROR; } @@ -841,9 +844,9 @@ ssize_t _gnutls_handshake_io_recv_int( GNUTLS_STATE state, ContentType type, Han if (dsize > 0 && (i==GNUTLS_E_INTERRUPTED || i==GNUTLS_E_AGAIN)) { gnutls_assert(); - state->gnutls_internals.handshake_recv_buffer.data = gnutls_realloc_fast( + state->gnutls_internals.handshake_recv_buffer.data = gnutls_realloc( state->gnutls_internals.handshake_recv_buffer.data, dsize); - if (state->gnutls_internals.handshake_recv_buffer.data==NULL) { + if (state->gnutls_internals.handshake_recv_buffer.data==NULL && dsize > 0) { gnutls_assert(); return GNUTLS_E_MEMORY_ERROR; } diff --git a/lib/gnutls_constate.c b/lib/gnutls_constate.c index a681427559..eb94db5e77 100644 --- a/lib/gnutls_constate.c +++ b/lib/gnutls_constate.c @@ -72,7 +72,7 @@ int _gnutls_set_keys(GNUTLS_STATE state, int hash_size, int IV_size, int key_siz if (ret<0) { gnutls_assert(); - gnutls_secure_free(key_block); + gnutls_free(key_block); return ret; } @@ -81,13 +81,13 @@ int _gnutls_set_keys(GNUTLS_STATE state, int hash_size, int IV_size, int key_siz pos = 0; if (hash_size > 0) { if (gnutls_sset_datum( &state->cipher_specs.client_write_mac_secret, &key_block[pos], hash_size) < 0 ) { - gnutls_secure_free(key_block); + gnutls_free(key_block); return GNUTLS_E_MEMORY_ERROR; } pos+=hash_size; if (gnutls_sset_datum( &state->cipher_specs.server_write_mac_secret, &key_block[pos], hash_size) < 0 ) { - gnutls_secure_free(key_block); + gnutls_free(key_block); return GNUTLS_E_MEMORY_ERROR; } pos+=hash_size; @@ -95,32 +95,32 @@ int _gnutls_set_keys(GNUTLS_STATE state, int hash_size, int IV_size, int key_siz if (key_size > 0) { if (gnutls_sset_datum( &state->cipher_specs.client_write_key, &key_block[pos], key_size) < 0 ) { - gnutls_secure_free(key_block); + gnutls_free(key_block); return GNUTLS_E_MEMORY_ERROR; } pos+=key_size; if (gnutls_sset_datum( &state->cipher_specs.server_write_key, &key_block[pos], key_size) < 0 ) { - gnutls_secure_free(key_block); + gnutls_free(key_block); return GNUTLS_E_MEMORY_ERROR; } pos+=key_size; } if (IV_size > 0) { if (gnutls_sset_datum( &state->cipher_specs.client_write_IV, &key_block[pos], IV_size) < 0 ) { - gnutls_secure_free(key_block); + gnutls_free(key_block); return GNUTLS_E_MEMORY_ERROR; } pos+=IV_size; if (gnutls_sset_datum( &state->cipher_specs.server_write_IV, &key_block[pos], IV_size) < 0 ) { - gnutls_secure_free(key_block); + gnutls_free(key_block); return GNUTLS_E_MEMORY_ERROR; } pos+=IV_size; } - gnutls_secure_free(key_block); + gnutls_free(key_block); state->cipher_specs.generated_keys = 1; diff --git a/lib/gnutls_datum.c b/lib/gnutls_datum.c index 7f5eb9032f..4ee896752b 100644 --- a/lib/gnutls_datum.c +++ b/lib/gnutls_datum.c @@ -87,7 +87,7 @@ void gnutls_free_datum( gnutls_datum* dat) { void gnutls_sfree_datum( gnutls_datum* dat) { if (dat->data!=NULL && dat->size!=0) - gnutls_secure_free( dat->data); + gnutls_free( dat->data); dat->data = NULL; dat->size = 0; diff --git a/lib/gnutls_dh_primes.c b/lib/gnutls_dh_primes.c index ab9641f8d7..e1e051b05d 100644 --- a/lib/gnutls_dh_primes.c +++ b/lib/gnutls_dh_primes.c @@ -338,7 +338,8 @@ void _gnutls_dh_clear_mpis(void) */ int _gnutls_dh_calc_mpis(void) { - int i, n; + int i; + size_t n; if (_gnutls_dh_default_params == NULL) { gnutls_assert(); @@ -536,8 +537,9 @@ int gnutls_dh_params_set(GNUTLS_DH_PARAMS dh_params, gnutls_datum prime, gnutls_datum generator, int bits) { GNUTLS_MPI tmp_prime, tmp_g; - int siz = 0, i = 0; - GNUTLS_DH_PARAMS sprime; + int i = 0; + GNUTLS_DH_PARAMS sprime=NULL; + size_t siz = 0; if (check_bits(bits) < 0) { gnutls_assert(); @@ -551,6 +553,9 @@ int gnutls_dh_params_set(GNUTLS_DH_PARAMS dh_params, gnutls_datum prime, break; } } while (dh_params[++i].bits != 0); + /* sprime is not null, because of the check_bits() + * above. + */ siz = prime.size; if (_gnutls_mpi_scan(&tmp_prime, prime.data, &siz)) { @@ -672,7 +677,7 @@ int gnutls_dh_params_generate(gnutls_datum * prime, { GNUTLS_MPI tmp_prime, tmp_g; - int siz; + size_t siz; if (check_bits(bits) < 0) { gnutls_assert(); diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c index bf7328c573..35ab543726 100644 --- a/lib/gnutls_global.c +++ b/lib/gnutls_global.c @@ -70,6 +70,49 @@ static void dlog( const char* str) { #endif } +extern void* (*gnutls_secure_malloc)(size_t); +extern void* (*gnutls_malloc)(size_t); +extern void (*gnutls_free)(void*); +extern int (*_gnutls_is_secure_memory)(const void*); +extern void* (*gnutls_realloc)(void*, size_t); + +int _gnutls_is_secure_mem_null( const void*); + +/** + * gnutls_global_set_mem_func - This function sets the memory allocation functions + * @alloc_func: it's the default memory allocation function. Like malloc(). + * @secure_alloc_func: This is the memory allocation function that will be used for sensitive data. + * @is_secure_func: a function that returns 0 if the memory given is not secure. May be NULL. + * @realloc_func: A realloc function + * @free_func: The function that frees allocated data. + * + * This is the function were you set the memory allocation functions gnutls + * is going to use. By default the libc's allocation functions (malloc(), free()), + * are used by gnutls, to allocate both sensitive and not sensitive data. + * This function is provided to set the memory allocation functions to + * something other than the defaults (ie the gcrypt allocation functions). + * + * This function must be called before gnutls_global_init() is called. + * + **/ +void gnutls_global_set_mem_func( + void *(*gnutls_alloc_func)(size_t), void* (*gnutls_secure_alloc_func)(size_t), + int (*gnutls_is_secure_func)(const void*), void *(*gnutls_realloc_func)(void *, size_t), + void (*gnutls_free_func)(void*)) +{ + gnutls_secure_malloc = gnutls_secure_alloc_func; + gnutls_malloc = gnutls_alloc_func; + gnutls_realloc = gnutls_realloc_func; + gnutls_free = gnutls_free_func; + + if (gnutls_is_secure_func==NULL) + _gnutls_is_secure_memory = gnutls_is_secure_func; + else + _gnutls_is_secure_memory = _gnutls_is_secure_mem_null; + + return; +} + static int _gnutls_init = 0; /** @@ -96,7 +139,7 @@ int gnutls_global_init( void) if (_gnutls_init!=1) { return 0; } - + if (gcry_control( GCRYCTL_ANY_INITIALIZATION_P) == 0) { /* for gcrypt in order to be able to allocate memory */ gcry_set_allocation_handler(gnutls_malloc, gnutls_secure_malloc, _gnutls_is_secure_memory, gnutls_realloc, gnutls_free); @@ -132,6 +175,7 @@ int gnutls_global_init( void) gnutls_assert(); return result; } + return 0; } diff --git a/lib/gnutls_handshake.c b/lib/gnutls_handshake.c index cf2ea02a29..9106d3b0ef 100644 --- a/lib/gnutls_handshake.c +++ b/lib/gnutls_handshake.c @@ -395,7 +395,7 @@ char * data; int _gnutls_send_finished(GNUTLS_STATE state, int again) { uint8 data[36]; - int ret; + int ret=0; int data_size = 0; diff --git a/lib/gnutls_mem.c b/lib/gnutls_mem.c index 91961dedd9..bcb1c26675 100644 --- a/lib/gnutls_mem.c +++ b/lib/gnutls_mem.c @@ -23,47 +23,15 @@ #include #include -#ifdef USE_LIBCALLOC +void* (*gnutls_secure_malloc)(size_t) = malloc; +void* (*gnutls_malloc)(size_t) = malloc; +void (*gnutls_free)(void*) = free; -int _gnutls_is_secure_memory(const void *ign) -{ - return 0; -} - -#else - -/* #define MALLOC_DEBUG */ -# define EXTRA_SIZE sizeof(size_t)+1 - -int _gnutls_is_secure_memory(const svoid * mem) -{ - if (mem==NULL) return 0; - return *((opaque *) mem - 1); -} +int _gnutls_is_secure_mem_null( const void* ign) { return 0; } -void *gnutls_malloc(size_t size) -{ - opaque *ret; - if (size == 0) - return NULL; +int (*_gnutls_is_secure_memory)(const void*) = _gnutls_is_secure_mem_null; +void* (*gnutls_realloc)(void*, size_t) = realloc; - ret = malloc(size + EXTRA_SIZE); - if (ret == NULL) - return ret; - - *((int *) ret) = size; - ret[sizeof(size_t)] = 0; /* not secure */ - - ret += EXTRA_SIZE; - -#ifdef MALLOC_DEBUG - _gnutls_log("Allocated: %x with %d bytes\n", ret, - _gnutls_malloc_ptr_size(ret)); -#endif - - return ret; - -} void *gnutls_calloc(size_t nmemb, size_t size) { @@ -77,93 +45,6 @@ void *gnutls_calloc(size_t nmemb, size_t size) return ret; } -size_t _gnutls_malloc_ptr_size(void *_ptr) -{ - opaque *ptr = _ptr; - - if (_ptr == NULL) - return 0; - - return *((int *) ((opaque *) ptr - sizeof(size_t) - 1)); -} - -void *gnutls_realloc(void *_ptr, size_t size) -{ - opaque *ret; - opaque* ptr = _ptr; - - if (ptr!=NULL) - ptr -= EXTRA_SIZE; - - ret = realloc(ptr, size + EXTRA_SIZE); - if (ret == NULL) - return ret; - - *((int *) ret) = size; - ret[sizeof(size_t)] = 0; /* not secure */ - - ret += EXTRA_SIZE; - - return ret; -} - -/* This realloc only returns a new pointer if you - * request more data than the data into the pointer. - */ -void *gnutls_realloc_fast(void *ptr, size_t size) -{ - - if (ptr != NULL && size <= _gnutls_malloc_ptr_size(ptr)) { - /* do nothing, just return the pointer. - * It's much faster. - */ - return ptr; - } - return gnutls_realloc(ptr, size); -} - -inline -static void _gnutls_free(void *_ptr) -{ -opaque *ptr = _ptr; - - - ptr -= EXTRA_SIZE; - -#ifdef MALLOC_DEBUG - _gnutls_log("Freed: %x with %d bytes\n", _ptr, - _gnutls_malloc_ptr_size(_ptr)); -#endif - free(ptr); -} - -void gnutls_free(void *_ptr) -{ - if (_ptr == NULL) - return; - - if ( _gnutls_is_secure_memory( _ptr) != 0) { - return gnutls_secure_free( _ptr); - } else { - _gnutls_free( _ptr); - } -} - - - -svoid *gnutls_secure_malloc(size_t size) -{ - opaque *ret; - ret = gnutls_malloc(size); - if (ret == NULL) - return ret; - - *((opaque *) ret - 1) = 1; /* secure mem */ - - return ret; - -} - svoid *gnutls_secure_calloc(size_t nmemb, size_t size) { svoid *ret; @@ -176,42 +57,6 @@ svoid *gnutls_secure_calloc(size_t nmemb, size_t size) return ret; } -size_t _gnutls_secure_ptr_size(svoid * ptr) -{ - return _gnutls_malloc_ptr_size(ptr); -} - -svoid *gnutls_secure_realloc(svoid * ptr, size_t size) -{ - svoid *ret; - if (ptr != NULL && size <= _gnutls_secure_ptr_size(ptr)) { - /* do not do realloc. - * return the previous pointer. - */ - return ptr; - } - ret = gnutls_secure_malloc(size); - if (ret == NULL) - return ret; - - if (ptr != NULL) { - memcpy(ret, ptr, GMIN(_gnutls_secure_ptr_size(ptr), size)); - gnutls_secure_free(ptr); - } - - return ret; -} - -void gnutls_secure_free(svoid * ptr) -{ -opaque* _ptr = ptr; - - memset(ptr, 0, _gnutls_secure_ptr_size(ptr)); - *((opaque *) _ptr - 1) = 0; /* not secure mem */ - - _gnutls_free(ptr); -} - char *gnutls_strdup(const char *s) { int size = strlen(s); @@ -225,5 +70,4 @@ char *gnutls_strdup(const char *s) return ret; } -#endif /* USE_LIBCALLOC */ diff --git a/lib/gnutls_mem.h b/lib/gnutls_mem.h index 9de14a0e94..aa0ab8e89a 100644 --- a/lib/gnutls_mem.h +++ b/lib/gnutls_mem.h @@ -5,7 +5,7 @@ # include #endif -typedef void svoid; /* for functions that allocate using gnutls_secure_free */ +typedef void svoid; /* for functions that allocate using gnutls_secure_malloc */ /* Use gnutls_afree() when calling alloca, or * memory leaks may occur in systems which do not @@ -19,36 +19,15 @@ typedef void svoid; /* for functions that allocate using gnutls_secure_free */ # define gnutls_afree gnutls_free #endif /* HAVE_ALLOCA */ -#ifdef USE_LIBCALLOC -# define gnutls_malloc malloc -# define gnutls_realloc realloc -# define gnutls_realloc_fast(x, y) (y==0?x:realloc(x, y)) -# define gnutls_free free -# define gnutls_calloc calloc -# define gnutls_secure_malloc malloc -# define gnutls_secure_realloc realloc -# define gnutls_secure_free free -# define gnutls_secure_calloc calloc -# define gnutls_strdup strdup -int _gnutls_is_secure_memory(const void*); +void* (*gnutls_secure_malloc)(size_t); +void* (*gnutls_malloc)(size_t); +void (*gnutls_free)(void*); +int (*_gnutls_is_secure_memory)(const void*); +void* (*gnutls_realloc)(void*, size_t); -#else - -svoid* gnutls_secure_malloc( size_t size); svoid* gnutls_secure_calloc( size_t nmemb, size_t size); -size_t _gnutls_secure_ptr_size( svoid* ptr); -svoid* gnutls_secure_realloc( svoid* ptr, size_t size); -void gnutls_secure_free( svoid* ptr); -int _gnutls_is_secure_memory(const svoid* mem); - -void* gnutls_malloc( size_t size); void* gnutls_calloc( size_t nmemb, size_t size); -size_t _gnutls_malloc_ptr_size( void* ptr); -void* gnutls_realloc( void* ptr, size_t size); -void* gnutls_realloc_fast( void* ptr, size_t size); -void gnutls_free( void* ptr); -char* gnutls_strdup( const char* s); -#endif +char* gnutls_strdup( const char* s); #endif /* GNUTLS_MEM_H */ diff --git a/lib/gnutls_pk.c b/lib/gnutls_pk.c index 9f83a42b93..7ef493a0e1 100644 --- a/lib/gnutls_pk.c +++ b/lib/gnutls_pk.c @@ -46,10 +46,10 @@ int _gnutls_pkcs1_rsa_encrypt(gnutls_datum * ciphertext, int params_len, int btype) { - int k, psize, i, ret, pad; + int i, ret, pad; GNUTLS_MPI m, res; opaque *edata, *ps; - + size_t k, psize; k = _gnutls_mpi_get_nbits(params[0]) / 8; @@ -165,9 +165,10 @@ int _gnutls_pkcs1_rsa_decrypt(gnutls_sdatum * plaintext, gnutls_datum ciphertext, GNUTLS_MPI* params, int params_len, int btype) { - int k, esize, i, ret; + int k, i, ret; GNUTLS_MPI c, res; opaque *edata; + size_t esize; k = _gnutls_mpi_get_nbits(params[0]) / 8; esize = ciphertext.size; @@ -303,8 +304,8 @@ static int encode_ber_rs( gnutls_datum* sig_value, GNUTLS_MPI r, GNUTLS_MPI s) { node_asn* sig; int result; opaque str[MAX_PARAMETER_SIZE]; -int len = sizeof(str); -int tot_len = 0; +size_t len = sizeof(str); +size_t tot_len = 0; if ((result=asn1_create_structure( _gnutls_get_gnutls_asn(), "GNUTLS.DSASignatureValue", &sig, "sig"))!=ASN_OK) { @@ -369,7 +370,8 @@ int _gnutls_dsa_sign(gnutls_datum * signature, const gnutls_datum *hash, GNUTLS_MPI * params, int params_len) { GNUTLS_MPI rs[2], mdata; - int k, ret; + int ret; + size_t k; k = hash->size; if (k!=20) { /* SHA only */ diff --git a/lib/gnutls_x509.c b/lib/gnutls_x509.c index bc7c6d3226..de2d10a797 100644 --- a/lib/gnutls_x509.c +++ b/lib/gnutls_x509.c @@ -254,7 +254,7 @@ time_t _gnutls_x509_get_time(node_asn * c2, char *root, char *when) { opaque ttime[MAX_TIME]; char name[1024]; - time_t ctime; + time_t ctime = (time_t)-1; int len, result; _gnutls_str_cpy(name, sizeof(name), root); @@ -1109,6 +1109,9 @@ static int parse_pem_cert_mem( gnutls_cert** cert_list, int* ncerts, gnutls_datum tmp; int ret, count; + ptr = input_cert; + siz = input_cert_size; + if (strstr( input_cert, "-----BEGIN PKCS7")!=NULL) { siz2 = _gnutls_fbase64_decode(ptr, siz, &b64); @@ -1120,9 +1123,6 @@ static int parse_pem_cert_mem( gnutls_cert** cert_list, int* ncerts, return ret; } - - ptr = input_cert; - siz = input_cert_size; i = *ncerts + 1; count = 0; diff --git a/lib/x509_b64.c b/lib/x509_b64.c index 9c3f89e738..380b77f795 100644 --- a/lib/x509_b64.c +++ b/lib/x509_b64.c @@ -351,7 +351,7 @@ int _gnutls_fbase64_decode( const uint8 * data, int data_size, gnutls_assert(); return -1; } - data_size -= (int)rdata-(int)data; + data_size -= (unsigned long int)rdata-(unsigned long int)data; if (data_size < 4 + strlen(bottom)) { gnutls_assert(); @@ -364,7 +364,7 @@ int _gnutls_fbase64_decode( const uint8 * data, int data_size, return -1; } data_size -= strlen(ENDSTR); - data_size -= (int)kdata-(int)rdata; + data_size -= (unsigned long int)kdata-(unsigned long int)rdata; rdata = kdata + strlen(ENDSTR); @@ -377,7 +377,7 @@ int _gnutls_fbase64_decode( const uint8 * data, int data_size, } /* position of kdata is before the ----END--- footer */ - rdata_size = (int)kdata-(int)rdata; + rdata_size = (unsigned long int)kdata-(unsigned long int)rdata; if (rdata_size < 4) { gnutls_assert(); diff --git a/libextra/auth_srp.c b/libextra/auth_srp.c index 89b7b36fcb..1dbb3649f9 100644 --- a/libextra/auth_srp.c +++ b/libextra/auth_srp.c @@ -300,7 +300,7 @@ int proc_srp_server_hello(GNUTLS_STATE state, const opaque * data, int data_size const uint8 *data_g; const uint8 *data_s; uint8 pwd_algo; - int i, ret; + int i, xx, ret; opaque hd[SRP_MAX_HASH_SIZE]; char *username; char *password; @@ -370,10 +370,11 @@ int proc_srp_server_hello(GNUTLS_STATE state, const opaque * data, int data_size /* generate x = SHA(s | SHA(U | ":" | p)) * (or the equivalent using bcrypt) */ - if ( ( ret =_gnutls_calc_srp_x( username, password, (opaque*)data_s, n_s, pwd_algo, &_n_g, hd)) < 0) { + if ( ( ret =_gnutls_calc_srp_x( username, password, (opaque*)data_s, n_s, pwd_algo, &xx, hd)) < 0) { gnutls_assert(); return ret; } + _n_g = xx; if (_gnutls_mpi_scan(&state->gnutls_key->x, hd, &_n_g) != 0 || state->gnutls_key->x==NULL) { gnutls_assert(); diff --git a/libextra/auth_srp_passwd.c b/libextra/auth_srp_passwd.c index 83b961b135..078719468a 100644 --- a/libextra/auth_srp_passwd.c +++ b/libextra/auth_srp_passwd.c @@ -44,6 +44,7 @@ int len; opaque *verifier; int verifier_size; int indx; +size_t xx; p = rindex( str, ':'); /* we have index */ if (p==NULL) { @@ -112,11 +113,12 @@ int indx; return GNUTLS_E_PARSING_ERROR; } - if (_gnutls_mpi_scan(&entry->v, verifier, &verifier_size) || entry->v == NULL) { + if (_gnutls_mpi_scan(&entry->v, verifier, &xx)) { gnutls_assert(); gnutls_free( entry->salt); return GNUTLS_E_MPI_SCAN_FAILED; } + verifier_size = xx; gnutls_free( verifier); @@ -141,7 +143,8 @@ static int pwd_put_values2( GNUTLS_SRP_PWD_ENTRY *entry, char *str, int str_size char * p; int len; opaque * tmp; -int tmp_size; +int ret; +size_t tmp_size; p = rindex( str, ':'); /* we have g */ if (p==NULL) { @@ -155,13 +158,15 @@ int tmp_size; /* read the generator */ len = strlen(p); if (p[len-1]=='\n' || p[len-1]==' ') len--; - tmp_size = _gnutls_sbase64_decode( p, len, &tmp); + ret = _gnutls_sbase64_decode( p, len, &tmp); - if (tmp_size < 0) { + if (ret < 0) { gnutls_assert(); return GNUTLS_E_PARSING_ERROR; } - if (_gnutls_mpi_scan(&entry->g, tmp, &tmp_size) || entry->g==NULL) { + + tmp_size = ret; + if (_gnutls_mpi_scan(&entry->g, tmp, &tmp_size)) { gnutls_assert(); gnutls_free(tmp); return GNUTLS_E_MPI_SCAN_FAILED; @@ -182,14 +187,15 @@ int tmp_size; p++; len = strlen(p); - tmp_size = _gnutls_sbase64_decode( p, len, &tmp); + ret = _gnutls_sbase64_decode( p, len, &tmp); - if (tmp_size < 0) { + if (ret < 0) { gnutls_assert(); _gnutls_mpi_release(&entry->g); return GNUTLS_E_PARSING_ERROR; } - if (_gnutls_mpi_scan(&entry->n, tmp, &tmp_size) || entry->n==NULL) { + tmp_size = ret; + if (_gnutls_mpi_scan(&entry->n, tmp, &tmp_size)) { gnutls_assert(); gnutls_free(tmp); _gnutls_mpi_release(&entry->g); @@ -385,7 +391,7 @@ int _gnutls_srp_generate_prime(opaque ** ret_g, opaque ** ret_n, int bits) { GNUTLS_MPI prime, g; - int siz; + size_t siz; char *tmp; if ( _gnutls_dh_generate_prime(&g, &prime, bits) < 0) { diff --git a/libextra/crypt_bcrypt.c b/libextra/crypt_bcrypt.c index e01bbca978..73cf342b01 100644 --- a/libextra/crypt_bcrypt.c +++ b/libextra/crypt_bcrypt.c @@ -602,13 +602,14 @@ static const char magic[] = "$2$"; char *crypt_bcrypt(const char* username, const char *passwd, const char *salt, GNUTLS_MPI g, GNUTLS_MPI n) { - unsigned char *sp; + unsigned char *sp, *spe; blf_ctx *ctx; unsigned char text[24]; uint8 *csalt; uint8 *rtext; uint8 cost; - int i, salt_size = strlen(salt), len; + int i, salt_size = strlen(salt); + size_t len; unsigned char *local_salt, *v; int passwd_len, vsize, tmpsize; opaque *tmp; @@ -636,11 +637,11 @@ char *crypt_bcrypt(const char* username, const char *passwd, const char *salt, G } sp++; - len = (int)rindex(sp, ':'); - if (len==0) { /* no ':' was found */ + spe = rindex(sp, ':'); + if (spe == NULL) { /* no ':' was found */ len = strlen(sp); - } else - len -= (int) sp; + } else + len = (unsigned long int)spe - (unsigned long int)sp; if (_gnutls_sbase64_decode(sp, len, &csalt) < 0) { gnutls_assert(); diff --git a/libextra/crypt_srpsha1.c b/libextra/crypt_srpsha1.c index aa7c64e6d1..cfeda1ca57 100644 --- a/libextra/crypt_srpsha1.c +++ b/libextra/crypt_srpsha1.c @@ -35,7 +35,7 @@ static const char magic[] = ""; char *crypt_srpsha1(const char *username, const char *passwd, const char *salt, GNUTLS_MPI g, GNUTLS_MPI n) { - unsigned char *sp, r1[MAX_HASH_SIZE]; + unsigned char *sp, *spe, r1[MAX_HASH_SIZE]; int salt_size = strlen(salt); unsigned char *local_salt, *v; int passwd_len; @@ -43,7 +43,8 @@ char *crypt_srpsha1(const char *username, const char *passwd, int vsize, hash_len = _gnutls_hash_get_algo_len(GNUTLS_MAC_SHA); opaque *tmp; uint8 *rtext, *csalt; - int rsalt_size, len, tmpsize; + int rsalt_size, tmpsize; + size_t len; passwd_len = strlen(passwd); /* we do not want the null */ @@ -69,11 +70,11 @@ char *crypt_srpsha1(const char *username, const char *passwd, } sp++; - len = (int)rindex(sp, ':'); - if (len==0) { /* parse error */ + spe = rindex(sp, ':'); + if (spe==NULL) { /* parse error */ len = strlen(sp); } else - len -= (int)sp; + len = (unsigned long int)spe - (unsigned long int)sp; rsalt_size = _gnutls_sbase64_decode(sp, len, &csalt); if (rsalt_size < 0) { diff --git a/libextra/gnutls_openpgp.c b/libextra/gnutls_openpgp.c index 88f56238e1..cbb8311ba2 100644 --- a/libextra/gnutls_openpgp.c +++ b/libextra/gnutls_openpgp.c @@ -46,7 +46,7 @@ typedef struct { int type; int armored; size_t size; - byte *data; + uint8 *data; } keybox_blob; typedef enum { @@ -67,9 +67,9 @@ release_mpi_array( GNUTLS_MPI *arr, size_t n ) } static u32 -buffer_to_u32( const byte *buffer ) +buffer_to_u32( const uint8 *buffer ) { - const byte *p = buffer; + const uint8 *p = buffer; if ( !p ) return 0; @@ -193,7 +193,7 @@ static byte* kbx_data_to_keyring( int type, int enc, const char *data, size_t size, size_t *r_size ) { - byte *p = NULL; + uint8 *p = NULL; if ( !data ) return NULL; @@ -1216,7 +1216,7 @@ int gnutls_openpgp_add_keyring_file(gnutls_datum *keyring, const char *name) { CDK_IOBUF inp = NULL; - byte *blob; + uint8 *blob; size_t nbytes; int enc = 0; int rc = 0; @@ -1256,7 +1256,7 @@ int gnutls_openpgp_add_keyring_mem(gnutls_datum *keyring, const char *data, size_t len) { - byte *blob; + uint8 *blob; size_t nbytes = 0; if (!keyring || !data || !len) diff --git a/libextra/gnutls_srp.c b/libextra/gnutls_srp.c index 850726f474..6e638018d1 100644 --- a/libextra/gnutls_srp.c +++ b/libextra/gnutls_srp.c @@ -39,14 +39,14 @@ int _gnutls_srp_gx(opaque * text, int textsize, opaque ** result, GNUTLS_MPI g, GNUTLS_MPI prime) { - GNUTLS_MPI x, e; - int result_size; + size_t result_size; - if (_gnutls_mpi_scan(&x, text, &textsize)) { + if (_gnutls_mpi_scan(&x, text, &result_size)) { gnutls_assert(); return GNUTLS_E_MPI_SCAN_FAILED; } + textsize = result_size; e = _gnutls_mpi_alloc_like(prime); if (e==NULL) { @@ -124,7 +124,7 @@ GNUTLS_MPI _gnutls_calc_srp_B(GNUTLS_MPI * ret_b, GNUTLS_MPI g, GNUTLS_MPI n, GN GNUTLS_MPI _gnutls_calc_srp_u(GNUTLS_MPI B) { - int b_size; + size_t b_size; opaque *b_holder, hd[MAX_HASH_SIZE]; GNUTLS_HASH_HANDLE td; uint32 u; diff --git a/src/common.c b/src/common.c index 9bb79fea7f..e8e7973449 100644 --- a/src/common.c +++ b/src/common.c @@ -33,7 +33,8 @@ void print_x509_info(GNUTLS_STATE state) int cert_list_size = 0; char digest[20]; char serial[40]; - int digest_size = sizeof(digest), i; + size_t digest_size = sizeof(digest); + int i; int serial_size = sizeof(serial); char printable[120]; char *print;