Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Unified Diff: sandbox/win/src/interception.cc

Issue 1342303003: Replace calls to rand_s with calls to RtlGenRandom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nit Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sandbox/win/sandbox_win.gypi ('k') | sandbox/win/src/interception_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/win/src/interception.cc
diff --git a/sandbox/win/src/interception.cc b/sandbox/win/src/interception.cc
index 283c9422352a083cad14a0fdbfd0a38fffcf7704..2fe864537d3ff6540cb053536b16a3a57b31b84a 100644
--- a/sandbox/win/src/interception.cc
+++ b/sandbox/win/src/interception.cc
@@ -17,24 +17,31 @@
#include "sandbox/win/src/interception_internal.h"
#include "sandbox/win/src/interceptors.h"
#include "sandbox/win/src/sandbox.h"
+#include "sandbox/win/src/sandbox_rand.h"
#include "sandbox/win/src/service_resolver.h"
#include "sandbox/win/src/target_interceptions.h"
#include "sandbox/win/src/target_process.h"
#include "sandbox/win/src/wow64.h"
+namespace sandbox {
+
namespace {
// Standard allocation granularity and page size for Windows.
const size_t kAllocGranularity = 65536;
const size_t kPageSize = 4096;
+} // namespace
+
+namespace internal {
+
// Find a random offset within 64k and aligned to ceil(log2(size)).
size_t GetGranularAlignedRandomOffset(size_t size) {
CHECK_LE(size, kAllocGranularity);
unsigned int offset;
do {
- rand_s(&offset);
+ GetRandom(&offset);
offset &= (kAllocGranularity - 1);
} while (offset > (kAllocGranularity - size));
@@ -46,9 +53,7 @@ size_t GetGranularAlignedRandomOffset(size_t size) {
return offset & ~(align_size - 1);
}
-} // namespace
-
-namespace sandbox {
+} // namespace internal
SANDBOX_INTERCEPT SharedMemory* g_interceptions;
@@ -394,7 +399,7 @@ bool InterceptionManager::PatchNtdll(bool hot_patch_needed) {
// Find an aligned, random location within the reserved range.
size_t thunk_bytes = interceptions_.size() * sizeof(ThunkData) +
sizeof(DllInterceptionData);
- size_t thunk_offset = GetGranularAlignedRandomOffset(thunk_bytes);
+ size_t thunk_offset = internal::GetGranularAlignedRandomOffset(thunk_bytes);
// Split the base and offset along page boundaries.
thunk_base += thunk_offset & ~(kPageSize - 1);
« no previous file with comments | « sandbox/win/sandbox_win.gypi ('k') | sandbox/win/src/interception_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698