summaryrefslogtreecommitdiff
path: root/regress/unittests/test_helper/fuzz.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2015-01-18 19:52:44 +0000
committerDamien Miller <djm@mindrot.org>2015-01-20 00:24:39 +1100
commit80603c0daa2538c349c1c152405580b164d5475f (patch)
treef9af28a55dfd54dd4b35053de8f19406ed6b9957 /regress/unittests/test_helper/fuzz.c
parent87d5495bd337e358ad69c524fcb9495208c0750b (diff)
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
Diffstat (limited to 'regress/unittests/test_helper/fuzz.c')
-rw-r--r--regress/unittests/test_helper/fuzz.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/regress/unittests/test_helper/fuzz.c b/regress/unittests/test_helper/fuzz.c
index 93cff6969..06fb247ef 100644
--- a/regress/unittests/test_helper/fuzz.c
+++ b/regress/unittests/test_helper/fuzz.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: fuzz.c,v 1.6 2015/01/18 19:50:55 djm Exp $ */ 1/* $OpenBSD: fuzz.c,v 1.7 2015/01/18 19:52:44 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -378,6 +378,14 @@ fuzz_next(struct fuzz *fuzz)
378} 378}
379 379
380int 380int
381fuzz_matches_original(struct fuzz *fuzz)
382{
383 if (fuzz_len(fuzz) != fuzz->slen)
384 return 0;
385 return memcmp(fuzz_ptr(fuzz), fuzz->seed, fuzz->slen) == 0;
386}
387
388int
381fuzz_done(struct fuzz *fuzz) 389fuzz_done(struct fuzz *fuzz)
382{ 390{
383 FUZZ_DBG(("fuzz = %p, strategies = 0x%lx", fuzz, 391 FUZZ_DBG(("fuzz = %p, strategies = 0x%lx", fuzz,