From a78f7fafc0285ea157ddfb433982c4210d735cc7 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Sat, 26 Sep 2009 15:00:42 +0000 Subject: [PATCH] Make the fuzzer a bit more useful by forcing 7-bit data into it. Getting valid UTF-8 sequences is quite unlikely, so we'd better just convert data to 7 bits and make it extra likely for escape sequences to occur. --- sys/teken/teken_stress.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sys/teken/teken_stress.c b/sys/teken/teken_stress.c index 40d09bf903b0..1f1c57253f09 100644 --- a/sys/teken/teken_stress.c +++ b/sys/teken/teken_stress.c @@ -92,13 +92,16 @@ stress_respond(void *s __unused, const void *buf __unused, size_t len __unused) { } +static const char replacement[] = + { 0x1b, '[', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';' }; + int main(int argc __unused, char *argv[] __unused) { teken_t t; int rnd; - unsigned int iteration = 0; - char buf[2048]; + unsigned int i, iteration = 0; + unsigned char buf[2048]; rnd = open("/dev/urandom", O_RDONLY); if (rnd < 0) { @@ -114,6 +117,12 @@ main(int argc __unused, char *argv[] __unused) exit(1); } + for (i = 0; i < sizeof buf; i++) { + if (buf[i] >= 0x80) + buf[i] = + replacement[buf[i] % sizeof replacement]; + } + teken_input(&t, buf, sizeof buf); iteration++;