summaryrefslogtreecommitdiff
path: root/puncture_fs
diff options
context:
space:
mode:
authorMohan Srinivasan <srmohan@google.com>2016-10-07 15:17:49 -0700
committerMohamad Ayyash <mkayyash@google.com>2016-10-10 21:12:54 +0000
commitbdcf7f23d5091c81565bc5011a639675f5f81826 (patch)
treec13457ce4dda3f3a0a5d535feed2946452797e0c /puncture_fs
parent067fecf89519831b6c72aed3fd41c0a7ffeaf8de (diff)
downloadextras-bdcf7f23d5091c81565bc5011a639675f5f81826.tar.gz
Fixes a segfault (divide by zero in create_unique_file()).
Don't pass in a zero size into create_unique_file(), since this function attempts to create and populate a file the asked size (it also causes a division by zero error when the size is zero). Test: Run puncture_fs several times to cover case where the random number generator returns value which would have caused size to be 0 (tested with debug printf to catch the case where we regenerated the random number). Change-Id: I397b92e2bc1e9164bb2b2e474a7135f81fc30b23 Signed-off-by: Mohan Srinivasan <srmohan@google.com>
Diffstat (limited to 'puncture_fs')
-rw-r--r--puncture_fs/puncture_fs.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/puncture_fs/puncture_fs.c b/puncture_fs/puncture_fs.c
index e9d08dc0..dbb4efce 100644
--- a/puncture_fs/puncture_fs.c
+++ b/puncture_fs/puncture_fs.c
@@ -163,6 +163,10 @@ static bool puncture_fs (const char * const path, const u64 total_size,
(int) (100.0 * starting_max / total_size));
hole_max = get_random_num(starting_max, ending_max);
+ do {
+ hole_max = get_random_num(starting_max, ending_max);
+ } while (hole_max == starting_max);
+
create_unique_file(stay_dir,
hole_max - starting_max,
file_id++,