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

Unified Diff: webrtc/base/helpers.cc

Issue 2115793003: Check that table evenly divides 256 when generating random string. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 4 years, 4 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 | « webrtc/base/helpers.h ('k') | webrtc/base/helpers_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/helpers.cc
diff --git a/webrtc/base/helpers.cc b/webrtc/base/helpers.cc
index b284cd7a73237b5c4608cd4dd7187c79d4029ed4..0eaf57b079f6dff344286419c955778c1ac45571 100644
--- a/webrtc/base/helpers.cc
+++ b/webrtc/base/helpers.cc
@@ -219,10 +219,15 @@ std::string CreateRandomString(size_t len) {
return str;
}
-bool CreateRandomString(size_t len,
+static bool CreateRandomString(size_t len,
const char* table, int table_size,
std::string* str) {
str->clear();
+ // Avoid biased modulo division below.
+ if (256 % table_size) {
+ LOG(LS_ERROR) << "Table size must divide 256 evenly!";
+ return false;
+ }
std::unique_ptr<uint8_t[]> bytes(new uint8_t[len]);
if (!Rng().Generate(bytes.get(), len)) {
LOG(LS_ERROR) << "Failed to generate random string!";
« no previous file with comments | « webrtc/base/helpers.h ('k') | webrtc/base/helpers_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698