From: Robert Spalek Date: Mon, 14 Jun 2004 17:21:50 +0000 (+0000) Subject: tested the wrapper guarding the safe decompression X-Git-Tag: holmes-import~1051 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=728e8c27a9fad3acb359d587e48298c88c18aa15;p=libucw.git tested the wrapper guarding the safe decompression --- diff --git a/lib/lizard-test.c b/lib/lizard-test.c index 38a76c56..2c5c1494 100644 --- a/lib/lizard-test.c +++ b/lib/lizard-test.c @@ -6,8 +6,9 @@ #include #include #include +#include -static char *options = CF_SHORT_OPTS "cdt"; +static char *options = CF_SHORT_OPTS "cdtx"; static char *help = "\ Usage: lizard-test input-file [output-file]\n\ \n\ @@ -16,6 +17,7 @@ CF_USAGE "-c\t\tCompress (default)\n\ -d\t\tDecompress\n\ -t\t\tCompress, decompress, and compare (in memory only)\n\ +-x, -xx, -xxx\tMake the test crash by underestimating the output buffer\n\ "; static void NONRET @@ -30,6 +32,7 @@ main(int argc, char **argv) { int opt; uns action = 'c'; + uns crash = 0; log_init(argv[0]); while ((opt = cf_getopt(argc, argv, options, CF_NO_LONG_OPTS, NULL)) >= 0) switch (opt) @@ -39,6 +42,9 @@ main(int argc, char **argv) case 't': action = opt; break; + case 'x': + crash++; + break; default: usage(); } @@ -47,7 +53,7 @@ main(int argc, char **argv) usage(); void *mi, *mo; - uns li, lo; + int li, lo; struct stat st; stat(argv[optind], &st); @@ -89,16 +95,43 @@ main(int argc, char **argv) } else { - void *mv; - uns lv; - mv = xmalloc(li); - lv = lizard_decompress(mo, mv); + struct lizard_buffer *buf = lizard_alloc(li); + uns exp_len = li; + if (crash==1) + { + if (exp_len >= PAGE_SIZE) + exp_len -= PAGE_SIZE; + else + exp_len = 0; + printf("Setting shorter output buffer to %d: ", exp_len); + fflush(stdout); + } + int lv = lizard_decompress_safe(mo, buf, exp_len); printf("-> %d ", lv); fflush(stdout); - if (lv != li || memcmp(mi, mv, lv)) + if (crash >= 2) + { + uns guarded_pos = (lv + PAGE_SIZE-1)/PAGE_SIZE * PAGE_SIZE; + printf("Reading from guarded memory: %d\n", ((byte *) (buf->ptr)) [guarded_pos]); + if (crash == 2) + { + printf("Writing to guarded memory: "); + fflush(stdout); + ((byte *) (buf->ptr)) [guarded_pos] = 0; + printf("succeeded\n"); + } + if (crash == 3) + { + printf("Reading behind guarded memory: "); + fflush(stdout); + printf("%d\n", ((byte *) (buf->ptr)) [guarded_pos + PAGE_SIZE] = 0); + } + } + if (lv != li || memcmp(mi, buf->ptr, li)) printf("WRONG"); else printf("OK"); + lizard_free(buf); } printf("\n"); }