summaryrefslogtreecommitdiff
path: root/lib/libcrypto/crypto
diff options
context:
space:
mode:
authorBrent Cook <bcook@cvs.openbsd.org>2014-08-28 01:00:58 +0000
committerBrent Cook <bcook@cvs.openbsd.org>2014-08-28 01:00:58 +0000
commit54a17f189070c0a2a8a349f9d7cf0c9013ce7d3b (patch)
treecbfabe874834f8ce61b2405e83f0a4350e219563 /lib/libcrypto/crypto
parent6bc19bc2cb948e05e9d5c33125230722cb0a9f60 (diff)
preserve errno value on success.
If getrandom returns a temporary failure, make sure errno is not polluted when it succeeds. Thanks to deraadt@ for pointing it out.
Diffstat (limited to 'lib/libcrypto/crypto')
-rw-r--r--lib/libcrypto/crypto/getentropy_linux.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/libcrypto/crypto/getentropy_linux.c b/lib/libcrypto/crypto/getentropy_linux.c
index 76d724af148..4e1a267931d 100644
--- a/lib/libcrypto/crypto/getentropy_linux.c
+++ b/lib/libcrypto/crypto/getentropy_linux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getentropy_linux.c,v 1.34 2014/08/16 18:42:41 bcook Exp $ */
+/* $OpenBSD: getentropy_linux.c,v 1.35 2014/08/28 01:00:57 bcook Exp $ */
/*
* Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org>
@@ -194,6 +194,7 @@ gotdata(char *buf, size_t len)
static int
getentropy_getrandom(void *buf, size_t len)
{
+ int pre_errno = errno;
int ret;
if (len > 256)
return (-1);
@@ -201,9 +202,10 @@ getentropy_getrandom(void *buf, size_t len)
ret = syscall(SYS_getrandom, buf, len, 0);
} while (ret == -1 && errno == EINTR);
- if (ret == len)
- return (0);
- return (-1);
+ if (ret != len)
+ return (-1);
+ errno = pre_errno;
+ return (0);
}
#endif