1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-20 10:37:24 -07:00

Limit safe_read() to SSIZE_MAX bytes

This commit is contained in:
Frank Denis 2015-11-21 08:33:08 +01:00
parent a39ab96afa
commit 68917b01cf
2 changed files with 10 additions and 0 deletions

View File

@ -45,6 +45,10 @@ BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);
# define HAVE_SAFE_ARC4RANDOM 1
#endif
#ifndef SSIZE_MAX
# define SSIZE_MAX (SIZE_MAX / 2 - 1)
#endif
typedef struct Salsa20Random_ {
unsigned char key[crypto_stream_salsa20_KEYBYTES];
unsigned char rnd32[16U * SALSA20_RANDOM_BLOCK_SIZE];
@ -97,6 +101,7 @@ safe_read(const int fd, void * const buf_, size_t size)
ssize_t readnb;
assert(size > (size_t) 0U);
assert(size <= SSIZE_MAX);
do {
while ((readnb = read(fd, buf, size)) < (ssize_t) 0 &&
(errno == EINTR || errno == EAGAIN)); /* LCOV_EXCL_LINE */

View File

@ -37,6 +37,10 @@ BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength);
# define HAVE_SAFE_ARC4RANDOM 1
#endif
#ifndef SSIZE_MAX
# define SSIZE_MAX (SIZE_MAX / 2 - 1)
#endif
#ifdef HAVE_SAFE_ARC4RANDOM
static uint32_t
@ -84,6 +88,7 @@ safe_read(const int fd, void * const buf_, size_t size)
ssize_t readnb;
assert(size > (size_t) 0U);
assert(size <= SSIZE_MAX);
do {
while ((readnb = read(fd, buf, size)) < (ssize_t) 0 &&
(errno == EINTR || errno == EAGAIN)); /* LCOV_EXCL_LINE */