From: djm Date: Sun, 18 Jan 2015 19:52:44 +0000 (+0000) Subject: add a fuzz_matches_original() function to the fuzzer to X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=60d08003695c4320e3b392beb0fad1a5db2b8222;p=openbsd add a fuzz_matches_original() function to the fuzzer to detect fuzz cases that are identical to the original data. Hacky implementation, but very useful when you need the fuzz to be different, e.g. when verifying signature --- diff --git a/regress/usr.bin/ssh/unittests/test_helper/fuzz.c b/regress/usr.bin/ssh/unittests/test_helper/fuzz.c index 2003fbe504f..392783bdabd 100644 --- a/regress/usr.bin/ssh/unittests/test_helper/fuzz.c +++ b/regress/usr.bin/ssh/unittests/test_helper/fuzz.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuzz.c,v 1.6 2015/01/18 19:50:55 djm Exp $ */ +/* $OpenBSD: fuzz.c,v 1.7 2015/01/18 19:52:44 djm Exp $ */ /* * Copyright (c) 2011 Damien Miller * @@ -373,6 +373,14 @@ fuzz_next(struct fuzz *fuzz) (u_long)fuzz->strategies, fuzz->o1, fuzz->o2, fuzz->slen)); } +int +fuzz_matches_original(struct fuzz *fuzz) +{ + if (fuzz_len(fuzz) != fuzz->slen) + return 0; + return memcmp(fuzz_ptr(fuzz), fuzz->seed, fuzz->slen) == 0; +} + int fuzz_done(struct fuzz *fuzz) { diff --git a/regress/usr.bin/ssh/unittests/test_helper/test_helper.h b/regress/usr.bin/ssh/unittests/test_helper/test_helper.h index b2a6f7c4a7e..6c630d7d56f 100644 --- a/regress/usr.bin/ssh/unittests/test_helper/test_helper.h +++ b/regress/usr.bin/ssh/unittests/test_helper/test_helper.h @@ -1,4 +1,4 @@ -/* $OpenBSD: test_helper.h,v 1.5 2015/01/15 07:36:28 djm Exp $ */ +/* $OpenBSD: test_helper.h,v 1.6 2015/01/18 19:52:44 djm Exp $ */ /* * Copyright (c) 2011 Damien Miller * @@ -279,6 +279,13 @@ void fuzz_cleanup(struct fuzz *fuzz); /* Prepare the next fuzz case in the series */ void fuzz_next(struct fuzz *fuzz); +/* + * Check whether this fuzz case is identical to the original + * This is slow, but useful if the caller needs to ensure that all tests + * generated change the input (e.g. when fuzzing signatures). + */ +int fuzz_matches_original(struct fuzz *fuzz); + /* Determine whether the current fuzz sequence is exhausted (nonzero = yes) */ int fuzz_done(struct fuzz *fuzz); @@ -288,4 +295,5 @@ u_char *fuzz_ptr(struct fuzz *fuzz); /* Dump the current fuzz case to stderr */ void fuzz_dump(struct fuzz *fuzz); + #endif /* _TEST_HELPER_H */