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)
|
void* get_random_bytes(const unsigned int count)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
int fd;
|
int fd, bytes_read;
|
||||||
|
|
||||||
buf = NOFAIL(malloc(count));
|
buf = NOFAIL(malloc(count));
|
||||||
fd = open(RANDOM_DEVICE, O_RDONLY);
|
fd = open(RANDOM_DEVICE, O_RDONLY);
|
||||||
@ -362,11 +362,13 @@ void* get_random_bytes(const unsigned int count)
|
|||||||
perror("open(" RANDOM_DEVICE ")");
|
perror("open(" RANDOM_DEVICE ")");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
if (read(fd, buf, count) != count) {
|
bytes_read = read(fd, buf, count);
|
||||||
if (count < 0)
|
if (bytes_read < 0) {
|
||||||
perror("read(" RANDOM_DEVICE ")");
|
perror("read(" RANDOM_DEVICE ")");
|
||||||
else
|
exit(2);
|
||||||
fprintf(stderr, "Short read of %s.\n", RANDOM_DEVICE);
|
}
|
||||||
|
if (bytes_read != count) {
|
||||||
|
fprintf(stderr, "Short read of %s.\n", RANDOM_DEVICE);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user