diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2015-01-18 19:52:45 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2015-01-18 19:52:45 +0000 |
commit | a56149a152e13d8b8fd8164740e8e6c5fd462678 (patch) | |
tree | ee5450c4998607174b20bab26236da8c52b271ba /regress | |
parent | 32bfff0e1845cc66004a22e3f55e1d2fdf72706d (diff) |
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
Diffstat (limited to 'regress')
-rw-r--r-- | regress/usr.bin/ssh/unittests/test_helper/fuzz.c | 10 | ||||
-rw-r--r-- | regress/usr.bin/ssh/unittests/test_helper/test_helper.h | 10 |
2 files changed, 18 insertions, 2 deletions
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 <djm@mindrot.org> * @@ -374,6 +374,14 @@ fuzz_next(struct fuzz *fuzz) } 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) { FUZZ_DBG(("fuzz = %p, strategies = 0x%lx", 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 <djm@mindrot.org> * @@ -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 */ |