diff options
author | Werner Koch <[email protected]> | 2007-02-12 14:13:37 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2007-02-12 14:13:37 +0000 |
commit | 22be39dfacf5c8d177926e91c50cac283c7c7853 (patch) | |
tree | 27076663ca4c69b043c6950d4c253d3515f3e159 | |
parent | * gpgkeys_ldap.c (send_key): Missing a free(). (diff) | |
download | gnupg-22be39dfacf5c8d177926e91c50cac283c7c7853.tar.gz gnupg-22be39dfacf5c8d177926e91c50cac283c7c7853.zip |
* secmem.c (ptr_into_pool_p): New.
(m_is_secure): Implement in terms of above. Also check that the
pool has been initialized.
-rw-r--r-- | util/ChangeLog | 6 | ||||
-rw-r--r-- | util/secmem.c | 19 |
2 files changed, 24 insertions, 1 deletions
diff --git a/util/ChangeLog b/util/ChangeLog index 0ea7427ce..890019ef7 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,9 @@ +2007-02-12 Werner Koch <[email protected]> + + * secmem.c (ptr_into_pool_p): New. + (m_is_secure): Implement in terms of above. Also check that the + pool has been initialized. + 2007-02-10 David Shaw <[email protected]> * http.c (do_parse_uri): Remove the hkp port 11371 detection. We diff --git a/util/secmem.c b/util/secmem.c index 5ffbfc6d3..a0248dae1 100644 --- a/util/secmem.c +++ b/util/secmem.c @@ -449,10 +449,27 @@ secmem_free( void *a ) cur_alloced -= size; } + +/* Check whether P points into the pool. */ +static int +ptr_into_pool_p (const void *p) +{ + /* We need to convert pointers to addresses. This is required by + C-99 6.5.8 to avoid undefined behaviour. Using size_t is at + least only implementation defined. See also + http://lists.gnupg.org/pipermail/gcrypt-devel/2007-February/001102.html + */ + size_t p_addr = (size_t)p; + size_t pool_addr = (size_t)pool; + + return p_addr >= pool_addr && p_addr < pool_addr+poolsize; +} + + int m_is_secure( const void *p ) { - return p >= pool && p < (void*)((char*)pool+poolsize); + return pool_okay && ptr_into_pool_p (p); } |