Mailing List Archive

[master] b3043ce14 Optimize VRND_RandomCrypto()
commit b3043ce14065266fe2d94b233357cbe3e74eff3f
Author: Nils Goroll <nils.goroll@uplex.de>
Date: Tue Jul 28 07:51:38 2020 +0200

Optimize VRND_RandomCrypto()

Try to read into the buffer in one go.

closes #3366

diff --git a/lib/libvarnish/vrnd.c b/lib/libvarnish/vrnd.c
index 778c31fb2..891c40f27 100644
--- a/lib/libvarnish/vrnd.c
+++ b/lib/libvarnish/vrnd.c
@@ -168,17 +168,19 @@ int
VRND_RandomCrypto(void *ptr, size_t len)
{
int fd;
- char *p;
+ char *p = ptr;
ssize_t l;

AN(ptr);
fd = open("/dev/urandom", O_RDONLY);
if (fd < 0)
return (-1);
- for (p = ptr; len > 0; len--, p++) {
- l = read(fd, p, 1);
- if (l != 1)
+ while (len > 0) {
+ l = read(fd, p, len);
+ if (l < 0)
break;
+ p += l;
+ len -= l;
}
closefd(&fd);
return (len == 0 ? 0 : -1);
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit