From d75af1030805a98ac7482fa7c6ceb6667cbe7f21 Mon Sep 17 00:00:00 2001 From: "jason.piao" Date: Mon, 24 Jun 2019 14:15:29 -0400 Subject: SERVER-41704 adding asn1 libfuzzer parser --- src/mongo/util/net/SConscript | 11 +++++++++ src/mongo/util/net/asn1_parser_fuzzer.cpp | 37 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/mongo/util/net/asn1_parser_fuzzer.cpp diff --git a/src/mongo/util/net/SConscript b/src/mongo/util/net/SConscript index daddb3c4ed0..c4ab9713f0b 100644 --- a/src/mongo/util/net/SConscript +++ b/src/mongo/util/net/SConscript @@ -205,6 +205,17 @@ env.CppUnitTest( ], ) +env.CppLibfuzzerTest( + target='asn1_parser_fuzzer', + source=[ + 'asn1_parser_fuzzer.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/base', + '$BUILD_DIR/mongo/util/net/ssl_manager', + ], +) + if get_option('ssl') == 'on': env.CppUnitTest( target='util_net_ssl_test', diff --git a/src/mongo/util/net/asn1_parser_fuzzer.cpp b/src/mongo/util/net/asn1_parser_fuzzer.cpp new file mode 100644 index 00000000000..f8e925028b8 --- /dev/null +++ b/src/mongo/util/net/asn1_parser_fuzzer.cpp @@ -0,0 +1,37 @@ +/** + * Copyright (C) 2019-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/base/data_range.h" +#include "mongo/util/net/ssl_manager.h" + +extern "C" int LLVMFuzzerTestOneInput(const char* Data, size_t Size) { + mongo::ConstDataRange dr = mongo::ConstDataRange(Data, Size); + auto ret = mongo::parsePeerRoles(dr); + return 0; +} -- cgit v1.2.1