diff options
author | Andy Shevchenko <andriy.shevchenko@linux.intel.com> | 2016-01-20 17:58:53 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-01-20 20:09:18 -0500 |
commit | a3d601fcc2f94fd1583053a1b1aea5de66ffc79c (patch) | |
tree | 1fc6649b564daf5a6cfe3622eb2bbaf66bbeba6e /lib/test_hexdump.c | |
parent | 3db4a987180acfba3bc117575bfedb81e055778c (diff) |
test_hexdump: go through all possible lengths of buffer
When test for overflow do iterate the buffer length in a range 0 ..
BUF_SIZE.
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/test_hexdump.c')
-rw-r--r-- | lib/test_hexdump.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index 1ecdb97b370c..940b1d318831 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c | |||
@@ -133,17 +133,16 @@ 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 | ||
136 | static void __init test_hexdump_overflow(bool ascii) | 136 | static void __init test_hexdump_overflow(size_t buflen, bool ascii) |
137 | { | 137 | { |
138 | char buf[56]; | 138 | char buf[TEST_HEXDUMP_BUF_SIZE]; |
139 | const char *t = test_data_1_le[0]; | 139 | const char *t = test_data_1_le[0]; |
140 | size_t l = get_random_int() % sizeof(buf); | ||
141 | bool a; | 140 | bool a; |
142 | int e, r; | 141 | int e, r; |
143 | 142 | ||
144 | memset(buf, FILL_CHAR, sizeof(buf)); | 143 | memset(buf, FILL_CHAR, sizeof(buf)); |
145 | 144 | ||
146 | r = hex_dump_to_buffer(data_b, 1, 16, 1, buf, l, ascii); | 145 | r = hex_dump_to_buffer(data_b, 1, 16, 1, buf, buflen, ascii); |
147 | 146 | ||
148 | if (ascii) | 147 | if (ascii) |
149 | e = 50; | 148 | e = 50; |
@@ -151,15 +150,15 @@ static void __init test_hexdump_overflow(bool ascii) | |||
151 | e = 2; | 150 | e = 2; |
152 | buf[e + 2] = '\0'; | 151 | buf[e + 2] = '\0'; |
153 | 152 | ||
154 | if (!l) { | 153 | if (!buflen) { |
155 | a = r == e && buf[0] == FILL_CHAR; | 154 | a = r == e && buf[0] == FILL_CHAR; |
156 | } else if (l < 3) { | 155 | } else if (buflen < 3) { |
157 | a = r == e && buf[0] == '\0'; | 156 | a = r == e && buf[0] == '\0'; |
158 | } else if (l < 4) { | 157 | } else if (buflen < 4) { |
159 | a = r == e && !strcmp(buf, t); | 158 | a = r == e && !strcmp(buf, t); |
160 | } else if (ascii) { | 159 | } else if (ascii) { |
161 | if (l < 51) | 160 | if (buflen < 51) |
162 | a = r == e && buf[l - 1] == '\0' && buf[l - 2] == FILL_CHAR; | 161 | a = r == e && buf[buflen - 1] == '\0' && buf[buflen - 2] == FILL_CHAR; |
163 | else | 162 | else |
164 | a = r == e && buf[50] == '\0' && buf[49] == '.'; | 163 | a = r == e && buf[50] == '\0' && buf[49] == '.'; |
165 | } else { | 164 | } else { |
@@ -167,7 +166,7 @@ static void __init test_hexdump_overflow(bool ascii) | |||
167 | } | 166 | } |
168 | 167 | ||
169 | if (!a) { | 168 | if (!a) { |
170 | pr_err("Len: %zu rc: %u strlen: %zu\n", l, r, strlen(buf)); | 169 | pr_err("Len: %zu rc: %u strlen: %zu\n", buflen, r, strlen(buf)); |
171 | pr_err("Result: '%s'\n", buf); | 170 | pr_err("Result: '%s'\n", buf); |
172 | } | 171 | } |
173 | } | 172 | } |
@@ -187,11 +186,11 @@ static int __init test_hexdump_init(void) | |||
187 | for (i = 0; i < 16; i++) | 186 | for (i = 0; i < 16; i++) |
188 | test_hexdump_set(rowsize, true); | 187 | test_hexdump_set(rowsize, true); |
189 | 188 | ||
190 | for (i = 0; i < 16; i++) | 189 | for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++) |
191 | test_hexdump_overflow(false); | 190 | test_hexdump_overflow(i, false); |
192 | 191 | ||
193 | for (i = 0; i < 16; i++) | 192 | for (i = 0; i <= TEST_HEXDUMP_BUF_SIZE; i++) |
194 | test_hexdump_overflow(true); | 193 | test_hexdump_overflow(i, true); |
195 | 194 | ||
196 | return -EINVAL; | 195 | return -EINVAL; |
197 | } | 196 | } |