summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_random_unittest.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-09-08 10:18:37 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-09-08 17:37:10 +0000
commite8b3e0cdcea319abf82639edb5e074ff94c4d66c (patch)
treeef41a1e8955acd12d92d1635b5e35ff9914efb3d /core/fxcrt/fx_random_unittest.cpp
parent808b52ac76bb5d9ee3e6a8371ddab25f62c8ed51 (diff)
downloadpdfium-e8b3e0cdcea319abf82639edb5e074ff94c4d66c.tar.xz
Fix one-second spin in fx_random.cpp
Take seed generation logic from base's address_space_randomization.cc. One small tweak is to avoid the bottom three bits of a stack address and invert, to make leaking ASLR more difficult along the lines of the freelist masking in base's partition allocator. Another tweak is to mix in some more time-based information. Another tweak is to add in the times called so that rapid successive calls return different results. Bug: pdfium:891 Change-Id: I14238da15cee9c8d4ca72d79e4f7fbb26997c619 Reviewed-on: https://pdfium-review.googlesource.com/13490 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/fx_random_unittest.cpp')
-rw-r--r--core/fxcrt/fx_random_unittest.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/core/fxcrt/fx_random_unittest.cpp b/core/fxcrt/fx_random_unittest.cpp
new file mode 100644
index 0000000000..607f1409b7
--- /dev/null
+++ b/core/fxcrt/fx_random_unittest.cpp
@@ -0,0 +1,24 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/fxcrt/fx_random.h"
+
+#include <array>
+#include <set>
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(FX_Random, GenerateMT3600times) {
+ // Prove this doesn't spin wait for a second each time.
+ // Since our global seeds are sequential, they wont't collide once
+ // seeded until 2^32 calls, and if the PNRG is any good, we won't
+ // get the same sequence from different seeds, esp. with this few
+ // iterations.
+ std::set<std::array<uint32_t, 16>> seen;
+ std::array<uint32_t, 16> current;
+ for (int i = 0; i < 3600; ++i) {
+ FX_Random_GenerateMT(current.data(), 16);
+ EXPECT_TRUE(seen.insert(current).second);
+ }
+}