[PATCH] D56146: [Sanitizer] enable arc4random api on Darwin
David CARLIER via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 29 01:12:11 PST 2018
devnexen created this revision.
devnexen added reviewers: vitalybuka, kubamracek.
devnexen created this object with visibility "All Users".
Herald added subscribers: Sanitizers, llvm-commits, fedor.sergeev.
- Also updating random helper to use other means, up to the code caller to provide proper buffer address, the maximum length taking care of before hand.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D56146
Files:
lib/sanitizer_common/sanitizer_mac.cc
lib/sanitizer_common/sanitizer_platform_interceptors.h
test/sanitizer_common/TestCases/Posix/arc4random.cc
Index: test/sanitizer_common/TestCases/Posix/arc4random.cc
===================================================================
--- test/sanitizer_common/TestCases/Posix/arc4random.cc
+++ test/sanitizer_common/TestCases/Posix/arc4random.cc
@@ -1,6 +1,6 @@
// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
//
-// UNSUPPORTED: linux, darwin, solaris
+// UNSUPPORTED: linux, solaris
#include <cstdlib>
#include <ctime>
Index: lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -546,6 +546,6 @@
#define SANITIZER_INTERCEPT_CDB SI_NETBSD
#define SANITIZER_INTERCEPT_VIS (SI_NETBSD || SI_FREEBSD)
#define SANITIZER_INTERCEPT_GETFSENT (SI_FREEBSD || SI_NETBSD || SI_MAC)
-#define SANITIZER_INTERCEPT_ARC4RANDOM (SI_FREEBSD || SI_NETBSD)
+#define SANITIZER_INTERCEPT_ARC4RANDOM (SI_FREEBSD || SI_NETBSD || SI_MAC)
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Index: lib/sanitizer_common/sanitizer_mac.cc
===================================================================
--- lib/sanitizer_common/sanitizer_mac.cc
+++ lib/sanitizer_common/sanitizer_mac.cc
@@ -67,6 +67,7 @@
#include <signal.h>
#include <stdlib.h>
#include <sys/mman.h>
+#include <sys/random.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
@@ -1116,8 +1117,10 @@
bool GetRandom(void *buffer, uptr length, bool blocking) {
if (!buffer || !length || length > 256)
return false;
- // arc4random never fails.
- arc4random_buf(buffer, length);
+ uptr rnd = getentropy(buffer, length);
+ int rverrno = 0;
+ if (internal_iserror(rnd, &rverrno) && rverrno == EINVAL)
+ return false;
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56146.179680.patch
Type: text/x-patch
Size: 1832 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181229/782f47d6/attachment.bin>
More information about the llvm-commits
mailing list