mirror of
https://github.com/rfc1036/whois.git
synced 2026-05-03 06:51:09 +00:00
mkpasswd: correctly report read(2) failures
They would always be reported as a short read.
This commit is contained in:
parent
9c0fbf514b
commit
0ba80dd8b3
14
mkpasswd.c
14
mkpasswd.c
@ -354,7 +354,7 @@ int main(int argc, char *argv[])
|
||||
void* get_random_bytes(const unsigned int count)
|
||||
{
|
||||
char *buf;
|
||||
int fd;
|
||||
int fd, bytes_read;
|
||||
|
||||
buf = NOFAIL(malloc(count));
|
||||
fd = open(RANDOM_DEVICE, O_RDONLY);
|
||||
@ -362,11 +362,13 @@ void* get_random_bytes(const unsigned int count)
|
||||
perror("open(" RANDOM_DEVICE ")");
|
||||
exit(2);
|
||||
}
|
||||
if (read(fd, buf, count) != count) {
|
||||
if (count < 0)
|
||||
perror("read(" RANDOM_DEVICE ")");
|
||||
else
|
||||
fprintf(stderr, "Short read of %s.\n", RANDOM_DEVICE);
|
||||
bytes_read = read(fd, buf, count);
|
||||
if (bytes_read < 0) {
|
||||
perror("read(" RANDOM_DEVICE ")");
|
||||
exit(2);
|
||||
}
|
||||
if (bytes_read != count) {
|
||||
fprintf(stderr, "Short read of %s.\n", RANDOM_DEVICE);
|
||||
exit(2);
|
||||
}
|
||||
close(fd);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user