summaryrefslogtreecommitdiffstats
path: root/crash_reporter
diff options
context:
space:
mode:
authorSteve Fung <stevefung@google.com>2015-09-12 03:21:59 -0700
committerSteve Fung <stevefung@google.com>2015-09-14 22:18:24 +0000
commit18ca9b364b75c14fa21c26ca93b8cd86776017c4 (patch)
treeca820cf5c6b11073cbb7ff1eea37313ca7a6d420 /crash_reporter
parentc372a778626dffdf6d1be5f98eafa966a95be082 (diff)
downloadcore-18ca9b364b75c14fa21c26ca93b8cd86776017c4.tar.gz
core-18ca9b364b75c14fa21c26ca93b8cd86776017c4.tar.bz2
core-18ca9b364b75c14fa21c26ca93b8cd86776017c4.zip
crash_reporter: Ensure crash_sender spread time is not negative
When calculating the crash_sender spread time, make sure that the random number is not negative when converted to a shell int variable. Bug: 24004011 Change-Id: I3b95dc244a26270ef2b93d5af4b0593a93eedcad
Diffstat (limited to 'crash_reporter')
-rwxr-xr-xcrash_reporter/crash_sender13
1 files changed, 12 insertions, 1 deletions
diff --git a/crash_reporter/crash_sender b/crash_reporter/crash_sender
index 7f9062afb..cb7c10c25 100755
--- a/crash_reporter/crash_sender
+++ b/crash_reporter/crash_sender
@@ -180,10 +180,21 @@ is_device_coredump_upload_allowed() {
}
# Generate a uniform random number in 0..max-1.
+# POSIX arithmetic expansion requires support of at least signed long integers.
+# On 32-bit systems, that may mean 32-bit signed integers, in which case the
+# 32-bit random number read from /dev/urandom may be interpreted as negative
+# when used inside an arithmetic expansion (since the high bit might be set).
+# mksh at least is known to behave this way.
+# For this case, simply take the absolute value, which will still give a
+# roughly uniform random distribution for the modulo (as we are merely ignoring
+# the high/sign bit).
+# See corresponding Arithmetic Expansion and Arithmetic Expression sections:
+# POSIX: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_04
+# mksh: http://linux.die.net/man/1/mksh
generate_uniform_random() {
local max=$1
local random="$(od -An -N4 -tu /dev/urandom)"
- echo $((random % max))
+ echo $(((random < 0 ? -random : random) % max))
}
# Check if sending a crash now does not exceed the maximum 24hr rate and