Displaying 8 results from an estimated 8 matches for "read_random".
2016 Jul 29
2
getrandom waits for a long time when /dev/random is insufficiently read from
...wrote:
> And finally, you have a coding error that is very very common but fatal when
> reading from /dev/random: you do not account for short reads which implies
> that your loop continues even in the case of short reads.
>
> Fix your code with something like the following:
> int read_random(char *buf, size_t buflen)
> {
> int fd = 0;
> ssize_t ret = 0;
> size_t len = 0;
>
> fd = open("/dev/random", O_RDONLY|O_CLOEXEC);
> if(0 > fd)
> return fd;
> do {
> ret = read...
2016 Jul 29
2
getrandom waits for a long time when /dev/random is insufficiently read from
...wrote:
> And finally, you have a coding error that is very very common but fatal when
> reading from /dev/random: you do not account for short reads which implies
> that your loop continues even in the case of short reads.
>
> Fix your code with something like the following:
> int read_random(char *buf, size_t buflen)
> {
> int fd = 0;
> ssize_t ret = 0;
> size_t len = 0;
>
> fd = open("/dev/random", O_RDONLY|O_CLOEXEC);
> if(0 > fd)
> return fd;
> do {
> ret = read...
2016 Jul 28
2
getrandom waits for a long time when /dev/random is insufficiently read from
Linux 4.6, also tried 4.7, qemu 2.6, using this C program:
#include <fcntl.h>
#include <stdlib.h>
#include <syscall.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
char buf[16];
int fd;
if (argc != 2)
return 1;
for (int i = 0; i < atoi(argv[1]); i++) {
sleep(1);
if ((fd = open("/dev/random", O_RDONLY)) ==
2016 Jul 28
2
getrandom waits for a long time when /dev/random is insufficiently read from
Linux 4.6, also tried 4.7, qemu 2.6, using this C program:
#include <fcntl.h>
#include <stdlib.h>
#include <syscall.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
char buf[16];
int fd;
if (argc != 2)
return 1;
for (int i = 0; i < atoi(argv[1]); i++) {
sleep(1);
if ((fd = open("/dev/random", O_RDONLY)) ==
2016 Jul 29
0
getrandom waits for a long time when /dev/random is insufficiently read from
...getrandom will wait that
long.
And finally, you have a coding error that is very very common but fatal when
reading from /dev/random: you do not account for short reads which implies
that your loop continues even in the case of short reads.
Fix your code with something like the following:
int read_random(char *buf, size_t buflen)
{
int fd = 0;
ssize_t ret = 0;
size_t len = 0;
fd = open("/dev/random", O_RDONLY|O_CLOEXEC);
if(0 > fd)
return fd;
do {
ret = read(fd, (buf + len), (buflen - len));...
2016 Jul 29
0
getrandom waits for a long time when /dev/random is insufficiently read from
...coding error that is very very common but
> > fatal when reading from /dev/random: you do not account for short
> > reads which implies that your loop continues even in the case of
> > short reads.
> >
> > Fix your code with something like the following:
> > int read_random(char *buf, size_t buflen)
> > {
> > int fd = 0;
> > ssize_t ret = 0;
> > size_t len = 0;
> >
> > fd = open("/dev/random", O_RDONLY|O_CLOEXEC);
> > if(0 > fd)
> > return fd;
> >...
2016 Jul 29
2
getrandom waits for a long time when /dev/random is insufficiently read from
...common but
> > > fatal when reading from /dev/random: you do not account for short
> > > reads which implies that your loop continues even in the case of
> > > short reads.
> > >
> > > Fix your code with something like the following:
> > > int read_random(char *buf, size_t buflen)
> > > {
> > >
> > > int fd = 0;
> > > ssize_t ret = 0;
> > > size_t len = 0;
> > >
> > > fd = open("/dev/random", O_RDONLY|O_CLOEXEC);
> > >...
2016 Jul 29
2
getrandom waits for a long time when /dev/random is insufficiently read from
...common but
> > > fatal when reading from /dev/random: you do not account for short
> > > reads which implies that your loop continues even in the case of
> > > short reads.
> > >
> > > Fix your code with something like the following:
> > > int read_random(char *buf, size_t buflen)
> > > {
> > >
> > > int fd = 0;
> > > ssize_t ret = 0;
> > > size_t len = 0;
> > >
> > > fd = open("/dev/random", O_RDONLY|O_CLOEXEC);
> > >...