Because the result of read() was incorrectly stored in an unsigned
variable, an error reading from the random number generator device would
result in an infinite loop that would start writing out of bounds and
eventually corrupt the stack.
char *out = vout;
while(outlen) {
- size_t len = read(random_fd, out, outlen);
+ ssize_t len = read(random_fd, out, outlen);
if(len <= 0) {
- if(errno == EAGAIN || errno == EINTR) {
+ if(len == -1 && (errno == EAGAIN || errno == EINTR)) {
continue;
}
char *out = vout;
while(outlen) {
- size_t len = read(random_fd, out, outlen);
+ ssize_t len = read(random_fd, out, outlen);
if(len <= 0) {
- if(errno == EAGAIN || errno == EINTR) {
+ if(len == -1 && (errno == EAGAIN || errno == EINTR)) {
continue;
}