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

Issue 1419703005: Add missing overflow handling to base::RandInt(). (Closed)

Created:
5 years, 1 month ago by Nico
Modified:
5 years, 1 month ago
Reviewers:
Lei Zhang
CC:
chromium-reviews, vmpstr+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Add missing overflow handling to base::RandInt(). The result of RandGenerator() could return a number as high as UINT_MAX, so casting that to int and adding it to another int will in general overflow. Overflow is undefined behavior for signed integers, so add some type casting to make sure this doesn't happen. The DCHECKs in RandInt() where catching that something fishy was going on (see bug), so as test just call RandInt() a few times with large bounds. This test made the DCHECK reliably fire without the fix. BUG=548375 R=thestig@chromium.org Committed: https://crrev.com/0a3852a7502c50ae8056090207c85c424804e706 Cr-Commit-Position: refs/heads/master@{#356939}

Patch Set 1 #

Total comments: 2

Patch Set 2 : stdint hyyyyyyype #

Unified diffs Side-by-side diffs Delta from patch set Stats (+18 lines, -10 lines) Patch
M base/rand_util.cc View 1 4 chunks +11 lines, -9 lines 0 comments Download
M base/rand_util_unittest.cc View 1 chunk +7 lines, -1 line 0 comments Download

Messages

Total messages: 10 (4 generated)
Nico
5 years, 1 month ago (2015-10-29 15:47:23 UTC) #2
Lei Zhang
lgtm https://codereview.chromium.org/1419703005/diff/1/base/rand_util.cc File base/rand_util.cc (right): https://codereview.chromium.org/1419703005/diff/1/base/rand_util.cc#newcode26 base/rand_util.cc:26: static_cast<int>(min + static_cast<int64>(base::RandGenerator(range))); int64_t, and fix line 22 ...
5 years, 1 month ago (2015-10-29 16:38:15 UTC) #3
Nico
https://codereview.chromium.org/1419703005/diff/1/base/rand_util.cc File base/rand_util.cc (right): https://codereview.chromium.org/1419703005/diff/1/base/rand_util.cc#newcode26 base/rand_util.cc:26: static_cast<int>(min + static_cast<int64>(base::RandGenerator(range))); On 2015/10/29 16:38:15, Lei Zhang wrote: ...
5 years, 1 month ago (2015-10-29 16:46:45 UTC) #4
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1419703005/20001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1419703005/20001
5 years, 1 month ago (2015-10-29 16:47:07 UTC) #7
commit-bot: I haz the power
Try jobs failed on following builders: linux_android_rel_ng on tryserver.chromium.linux (JOB_FAILED, http://build.chromium.org/p/tryserver.chromium.linux/builders/linux_android_rel_ng/builds/88695)
5 years, 1 month ago (2015-10-29 17:52:01 UTC) #9
commit-bot: I haz the power
5 years, 1 month ago (2015-10-29 20:44:56 UTC) #10
Message was sent while issue was closed.
Patchset 2 (id:??) landed as
https://crrev.com/0a3852a7502c50ae8056090207c85c424804e706
Cr-Commit-Position: refs/heads/master@{#356939}

Powered by Google App Engine
This is Rietveld 408576698