From ad4da7fbc0779fb1730c9862221e19583de69f4f Mon Sep 17 00:00:00 2001 From: Kurt Roeckx Date: Sat, 19 Nov 2016 17:13:10 +0100 Subject: [PATCH] Add a FuzzerClean() function This allows to free everything we allocated, so we can detect memory leaks. Reviewed-by: Rich Salz GH: #2023 --- fuzz/asn1.c | 4 ++++ fuzz/asn1parse.c | 4 ++++ fuzz/bignum.c | 4 ++++ fuzz/bndiv.c | 4 ++++ fuzz/cms.c | 4 ++++ fuzz/conf.c | 4 ++++ fuzz/crl.c | 4 ++++ fuzz/ct.c | 4 ++++ fuzz/driver.c | 2 ++ fuzz/fuzzer.h | 1 + fuzz/server.c | 5 +++++ fuzz/test-corpus.c | 3 +++ fuzz/x509.c | 4 ++++ 13 files changed, 47 insertions(+) diff --git a/fuzz/asn1.c b/fuzz/asn1.c index 0644ed79e13..f7b5571d4f7 100644 --- a/fuzz/asn1.c +++ b/fuzz/asn1.c @@ -222,3 +222,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len) return 0; } + +void FuzzerCleanup(void) +{ +} diff --git a/fuzz/asn1parse.c b/fuzz/asn1parse.c index 2fba1c44b6a..edb4d023030 100644 --- a/fuzz/asn1parse.c +++ b/fuzz/asn1parse.c @@ -33,3 +33,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len) (void)ASN1_parse_dump(bio_out, buf, len, 0, 0); return 0; } + +void FuzzerCleanup(void) +{ +} diff --git a/fuzz/bignum.c b/fuzz/bignum.c index 9e110f65ef4..d6e8637a98d 100644 --- a/fuzz/bignum.c +++ b/fuzz/bignum.c @@ -94,3 +94,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len) return 0; } + +void FuzzerCleanup(void) +{ +} diff --git a/fuzz/bndiv.c b/fuzz/bndiv.c index 93198786079..eb17f29cab5 100644 --- a/fuzz/bndiv.c +++ b/fuzz/bndiv.c @@ -107,3 +107,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len) return 0; } + +void FuzzerCleanup(void) +{ +} diff --git a/fuzz/cms.c b/fuzz/cms.c index 71d8b6953c9..c4477efa8fd 100644 --- a/fuzz/cms.c +++ b/fuzz/cms.c @@ -36,3 +36,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len) BIO_free(in); return 0; } + +void FuzzerCleanup(void) +{ +} diff --git a/fuzz/conf.c b/fuzz/conf.c index 49edb3eaa69..27429c570f1 100644 --- a/fuzz/conf.c +++ b/fuzz/conf.c @@ -38,3 +38,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len) return 0; } + +void FuzzerCleanup(void) +{ +} diff --git a/fuzz/crl.c b/fuzz/crl.c index 51d184363ad..decf19e9d3e 100644 --- a/fuzz/crl.c +++ b/fuzz/crl.c @@ -35,3 +35,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len) } return 0; } + +void FuzzerCleanup(void) +{ +} diff --git a/fuzz/ct.c b/fuzz/ct.c index 636b1951099..47b0fc3f78a 100644 --- a/fuzz/ct.c +++ b/fuzz/ct.c @@ -40,3 +40,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len) } return 0; } + +void FuzzerCleanup(void) +{ +} diff --git a/fuzz/driver.c b/fuzz/driver.c index d4b11cd6a47..21bbb255afe 100644 --- a/fuzz/driver.c +++ b/fuzz/driver.c @@ -40,6 +40,8 @@ int main(int argc, char** argv) FuzzerTestOneInput(buf, size); free(buf); } + + FuzzerCleanup(); return 0; } diff --git a/fuzz/fuzzer.h b/fuzz/fuzzer.h index 04d605d79a2..5f9efa4bf6b 100644 --- a/fuzz/fuzzer.h +++ b/fuzz/fuzzer.h @@ -10,3 +10,4 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len); int FuzzerInitialize(int *argc, char ***argv); +void FuzzerCleanup(void); diff --git a/fuzz/server.c b/fuzz/server.c index 26ef4da1e64..b8a3ac44e38 100644 --- a/fuzz/server.c +++ b/fuzz/server.c @@ -250,3 +250,8 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len) SSL_free(server); return 0; } + +void FuzzerCleanup(void) +{ + SSL_CTX_free(ctx); +} diff --git a/fuzz/test-corpus.c b/fuzz/test-corpus.c index c553697d6c7..9cef01f86d9 100644 --- a/fuzz/test-corpus.c +++ b/fuzz/test-corpus.c @@ -42,5 +42,8 @@ int main(int argc, char **argv) { free(buf); fclose(f); } + + FuzzerCleanup(); + return 0; } diff --git a/fuzz/x509.c b/fuzz/x509.c index 4c5b73258d5..78fef6c3ff0 100644 --- a/fuzz/x509.c +++ b/fuzz/x509.c @@ -36,3 +36,7 @@ int FuzzerTestOneInput(const uint8_t *buf, size_t len) } return 0; } + +void FuzzerCleanup(void) +{ +} -- 2.47.2