upstream commit

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
This commit is contained in:
djm@openbsd.org 2015-01-18 19:52:44 +00:00 committed by Damien Miller
parent 87d5495bd3
commit 80603c0daa
2 changed files with 18 additions and 2 deletions

View File

@ -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>
*
@ -377,6 +377,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)
{

View File

@ -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>
*
@ -283,6 +283,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);
@ -292,4 +299,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 */