aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2016-01-20 17:59:04 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-20 20:09:18 -0500
commit1dacd9ddd359eed63b210bd9b5000c2cfae287ff (patch)
tree76baf50b411c76191f0cbca6b398d9c0a9ed15d1 /lib
parentcc77a719a5cfd419d057277fd0fdfca568bcfdd2 (diff)
test_hexdump: test all possible group sizes for overflow
Currently the only one combination is tested for overflow, i.e. rowsize = 16, groupsize = 1, len = 1. Do various test to go through all possible branches. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/test_hexdump.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c
index 16a759374730..11d45f510d6c 100644
--- a/lib/test_hexdump.c
+++ b/lib/test_hexdump.c
@@ -133,7 +133,9 @@ static void __init test_hexdump_set(int rowsize, bool ascii)
133 test_hexdump(len, rowsize, 1, ascii); 133 test_hexdump(len, rowsize, 1, ascii);
134} 134}
135 135
136static void __init test_hexdump_overflow(size_t buflen, bool ascii) 136static void __init test_hexdump_overflow(size_t buflen, size_t len,
137 int rowsize, int groupsize,
138 bool ascii)
137{ 139{
138 char test[TEST_HEXDUMP_BUF_SIZE]; 140 char test[TEST_HEXDUMP_BUF_SIZE];
139 char buf[TEST_HEXDUMP_BUF_SIZE]; 141 char buf[TEST_HEXDUMP_BUF_SIZE];
@@ -176,6 +178,19 @@ static void __init test_hexdump_overflow(size_t buflen, bool ascii)
176 } 178 }
177} 179}
178 180
181static void __init test_hexdump_overflow_set(size_t buflen, bool ascii)
182{
183 unsigned int i = 0;
184 int rs = (get_random_int() % 2 + 1) * 16;
185
186 do {
187 int gs = 1 << i;
188 size_t len = get_random_int() % rs + gs;
189
190 test_hexdump_overflow(buflen, rounddown(len, gs), rs, gs, ascii);
191 } while (i++ < 3);
192}
193
179static int __init test_hexdump_init(void) 194static int __init test_hexdump_init(void)
180{ 195{
181 unsigned int i; 196 unsigned int i;
@@ -192,10 +207,10 @@ static int __init test_hexdump_init(void)
192 test_hexdump_set(rowsize, true); 207 test_hexdump_set(rowsize, true);
193 208
194 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++) 209 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
195 test_hexdump_overflow(i, false); 210 test_hexdump_overflow_set(i, false);
196 211
197 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++) 212 for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++)
198 test_hexdump_overflow(i, true); 213 test_hexdump_overflow_set(i, true);
199 214
200 return -EINVAL; 215 return -EINVAL;
201} 216}