From 36ca21415a0ef94f304ba174700e53d48aaa58ab Mon Sep 17 00:00:00 2001 From: Martin Kreichgauer Date: Wed, 14 Dec 2016 13:44:10 -0800 Subject: [PATCH] crypto/rand: Fix a crash bug in RAND_enable_fork_unsafe_buffering. Change-Id: Ifff59b1518f513c1be70e4e0d4ed3430741d0a5e Reviewed-on: https://boringssl-review.googlesource.com/12860 Reviewed-by: Adam Langley Commit-Queue: Adam Langley CQ-Verified: CQ bot account: commit-bot@chromium.org --- crypto/rand/urandom.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crypto/rand/urandom.c b/crypto/rand/urandom.c index 17d194c5..14d2e8a3 100644 --- a/crypto/rand/urandom.c +++ b/crypto/rand/urandom.c @@ -207,12 +207,12 @@ void RAND_enable_fork_unsafe_buffering(int fd) { abort(); // Already initialized } - if (urandom_fd == kHaveGetrandom) { - if (fd >= 0) { + if (fd >= 0) { + if (urandom_fd == kHaveGetrandom) { close(fd); + } else if (urandom_fd != fd) { + abort(); // Already initialized. } - } else if (urandom_fd != fd) { - abort(); // Already initialized. } }