diff options
author | Werner Koch <wk@gnupg.org> | 2014-04-15 16:40:48 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2014-04-22 10:34:52 +0200 |
commit | a79c4ad7c56ee4410f17beb73eeb58b0dd36bfc6 (patch) | |
tree | 4ad3be77edb80d246afdf5c8ea1552df4a573c3d /random | |
parent | 773e23698218755e9172d2507031a8263c47cc0b (diff) | |
download | libgcrypt-a79c4ad7c56ee4410f17beb73eeb58b0dd36bfc6.tar.gz |
random: Small patch for consistency and really burn the stack.
* random/rndlinux.c (_gcry_rndlinux_gather_random): s/int/size_t/.
(_gcry_rndlinux_gather_random): Replace memset by wipememory.
--
size_t was suggested by Marcus Meissner <meissner@suse.de>. While
looking at the code I identified the useless (i.e. likely optimized
away) memset.
Diffstat (limited to 'random')
-rw-r--r-- | random/rndlinux.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/random/rndlinux.c b/random/rndlinux.c index 89ac2031..9eeec574 100644 --- a/random/rndlinux.c +++ b/random/rndlinux.c @@ -226,21 +226,23 @@ _gcry_rndlinux_gather_random (void (*add)(const void*, size_t, do { - int nbytes = length < sizeof(buffer)? length : sizeof(buffer); - n = read(fd, buffer, nbytes ); - if( n >= 0 && n > nbytes ) + size_t nbytes; + + nbytes = length < sizeof(buffer)? length : sizeof(buffer); + n = read (fd, buffer, nbytes); + if (n >= 0 && n > nbytes) { log_error("bogus read from random device (n=%d)\n", n ); n = nbytes; } } - while( n == -1 && errno == EINTR ); - if ( n == -1 ) + while (n == -1 && errno == EINTR); + if (n == -1) log_fatal("read error on random device: %s\n", strerror(errno)); - (*add)( buffer, n, origin ); + (*add)(buffer, n, origin); length -= n; } - memset(buffer, 0, sizeof(buffer) ); + wipememory (buffer, sizeof buffer); if (any_need_entropy) _gcry_random_progress ("need_entropy", 'X', (int)want, (int)want); |