diff options
author | bcook <> | 2014-08-28 01:00:57 +0000 |
---|---|---|
committer | bcook <> | 2014-08-28 01:00:57 +0000 |
commit | 472401edb7fab3d9aa5240d5f046ed89cf3b4b98 (patch) | |
tree | 2fc7c3a3baa3b297386fa386f148df81bed7f216 /src | |
parent | cfb0c7a009844448f5c960b5f0e5bcf641f2f953 (diff) | |
download | openbsd-472401edb7fab3d9aa5240d5f046ed89cf3b4b98.tar.gz openbsd-472401edb7fab3d9aa5240d5f046ed89cf3b4b98.tar.bz2 openbsd-472401edb7fab3d9aa5240d5f046ed89cf3b4b98.zip |
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 'src')
-rw-r--r-- | src/lib/libcrypto/arc4random/getentropy_linux.c | 10 | ||||
-rw-r--r-- | src/lib/libcrypto/crypto/getentropy_linux.c | 10 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/lib/libcrypto/arc4random/getentropy_linux.c b/src/lib/libcrypto/arc4random/getentropy_linux.c index 76d724af14..4e1a267931 100644 --- a/src/lib/libcrypto/arc4random/getentropy_linux.c +++ b/src/lib/libcrypto/arc4random/getentropy_linux.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getentropy_linux.c,v 1.34 2014/08/16 18:42:41 bcook Exp $ */ | 1 | /* $OpenBSD: getentropy_linux.c,v 1.35 2014/08/28 01:00:57 bcook Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> | 4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> |
@@ -194,6 +194,7 @@ gotdata(char *buf, size_t len) | |||
194 | static int | 194 | static int |
195 | getentropy_getrandom(void *buf, size_t len) | 195 | getentropy_getrandom(void *buf, size_t len) |
196 | { | 196 | { |
197 | int pre_errno = errno; | ||
197 | int ret; | 198 | int ret; |
198 | if (len > 256) | 199 | if (len > 256) |
199 | return (-1); | 200 | return (-1); |
@@ -201,9 +202,10 @@ getentropy_getrandom(void *buf, size_t len) | |||
201 | ret = syscall(SYS_getrandom, buf, len, 0); | 202 | ret = syscall(SYS_getrandom, buf, len, 0); |
202 | } while (ret == -1 && errno == EINTR); | 203 | } while (ret == -1 && errno == EINTR); |
203 | 204 | ||
204 | if (ret == len) | 205 | if (ret != len) |
205 | return (0); | 206 | return (-1); |
206 | return (-1); | 207 | errno = pre_errno; |
208 | return (0); | ||
207 | } | 209 | } |
208 | #endif | 210 | #endif |
209 | 211 | ||
diff --git a/src/lib/libcrypto/crypto/getentropy_linux.c b/src/lib/libcrypto/crypto/getentropy_linux.c index 76d724af14..4e1a267931 100644 --- a/src/lib/libcrypto/crypto/getentropy_linux.c +++ b/src/lib/libcrypto/crypto/getentropy_linux.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getentropy_linux.c,v 1.34 2014/08/16 18:42:41 bcook Exp $ */ | 1 | /* $OpenBSD: getentropy_linux.c,v 1.35 2014/08/28 01:00:57 bcook Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> | 4 | * Copyright (c) 2014 Theo de Raadt <deraadt@openbsd.org> |
@@ -194,6 +194,7 @@ gotdata(char *buf, size_t len) | |||
194 | static int | 194 | static int |
195 | getentropy_getrandom(void *buf, size_t len) | 195 | getentropy_getrandom(void *buf, size_t len) |
196 | { | 196 | { |
197 | int pre_errno = errno; | ||
197 | int ret; | 198 | int ret; |
198 | if (len > 256) | 199 | if (len > 256) |
199 | return (-1); | 200 | return (-1); |
@@ -201,9 +202,10 @@ getentropy_getrandom(void *buf, size_t len) | |||
201 | ret = syscall(SYS_getrandom, buf, len, 0); | 202 | ret = syscall(SYS_getrandom, buf, len, 0); |
202 | } while (ret == -1 && errno == EINTR); | 203 | } while (ret == -1 && errno == EINTR); |
203 | 204 | ||
204 | if (ret == len) | 205 | if (ret != len) |
205 | return (0); | 206 | return (-1); |
206 | return (-1); | 207 | errno = pre_errno; |
208 | return (0); | ||
207 | } | 209 | } |
208 | #endif | 210 | #endif |
209 | 211 | ||