Skip to content

Commit

Permalink
ERR_clear_error at the end of each fuzzer.
Browse files Browse the repository at this point in the history
Data allocated in one fuzzer iteration and then freed in the next
complicates the leak checker. Avoid this by dropping hidden global state
at the end of each run.

Change-Id: Ice79704f2754a6b1f40e288df9b97ddd5b3b97d5
Reviewed-on: https://boringssl-review.googlesource.com/11600
Commit-Queue: David Benjamin <[email protected]>
Reviewed-by: Adam Langley <[email protected]>
  • Loading branch information
davidben authored and agl committed Oct 13, 2016
1 parent 1991af6 commit 4c0e6c6
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fuzz/cert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */

#include <openssl/err.h>
#include <openssl/mem.h>
#include <openssl/x509.h>

Expand All @@ -27,5 +28,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
OPENSSL_free(der);
}
X509_free(x509);
ERR_clear_error();
return 0;
}
2 changes: 2 additions & 0 deletions fuzz/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <assert.h>

#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/rsa.h>
Expand Down Expand Up @@ -290,5 +291,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
}
SSL_free(client);

ERR_clear_error();
return 0;
}
2 changes: 2 additions & 0 deletions fuzz/pkcs8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */

#include <openssl/bytestring.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/mem.h>

Expand All @@ -34,5 +35,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
}
CBB_cleanup(&cbb);
EVP_PKEY_free(pkey);
ERR_clear_error();
return 0;
}
2 changes: 2 additions & 0 deletions fuzz/privkey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */

#include <openssl/err.h>
#include <openssl/evp.h>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
EVP_PKEY_free(d2i_AutoPrivateKey(NULL, &buf, len));
ERR_clear_error();
return 0;
}
4 changes: 3 additions & 1 deletion fuzz/read_pem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */

#include <openssl/crypto.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/mem.h>
#include <openssl/pem.h>

Expand All @@ -32,5 +33,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {

BIO_free(bio);

ERR_clear_error();
return 0;
}
2 changes: 2 additions & 0 deletions fuzz/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <openssl/bio.h>
#include <openssl/dh.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/rsa.h>
Expand Down Expand Up @@ -289,5 +290,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
}
SSL_free(server);

ERR_clear_error();
return 0;
}
3 changes: 3 additions & 0 deletions fuzz/spki.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */

#include <openssl/bytestring.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/mem.h>

Expand All @@ -21,6 +22,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
CBS_init(&cbs, buf, len);
EVP_PKEY *pkey = EVP_parse_public_key(&cbs);
if (pkey == NULL) {
ERR_clear_error();
return 0;
}

Expand All @@ -34,5 +36,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
}
CBB_cleanup(&cbb);
EVP_PKEY_free(pkey);
ERR_clear_error();
return 0;
}
1 change: 1 addition & 0 deletions fuzz/ssl_ctx_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <assert.h>

#include <openssl/bytestring.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/rsa.h>
#include <openssl/ssl.h>
Expand Down

0 comments on commit 4c0e6c6

Please sign in to comment.