зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1371161: port SDP file parser to LibFuzzer r=decoder
MozReview-Commit-ID: FJhOdy2ZVqf --HG-- rename : media/webrtc/signaling/fuzztest/sdp_file_parser.cpp => media/webrtc/signaling/fuzztest/sdp_parser_libfuzz.cpp extra : rebase_source : f12c0e593212e077b694ef5732568e19c0a7fbed
This commit is contained in:
Родитель
3455fd8354
Коммит
66305cc2e0
|
@ -134,7 +134,11 @@ if CONFIG['MOZ_WEBRTC_SIGNALING']:
|
|||
|
||||
if CONFIG['ENABLE_TESTS']:
|
||||
TEST_DIRS += [
|
||||
'signaling/fuzztest',
|
||||
'signaling/gtest',
|
||||
'trunk/gtest',
|
||||
]
|
||||
|
||||
if CONFIG['FUZZING']:
|
||||
TEST_DIRS += [
|
||||
'signaling/fuzztest'
|
||||
]
|
||||
|
|
|
@ -3,47 +3,19 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
if CONFIG['OS_TARGET'] == 'Linux' or CONFIG['OS_TARGET'] == 'Darwin':
|
||||
DISABLE_STL_WRAPPING = True
|
||||
DEFINES['CPR_STRING_USE_FALLIBLE_MALLOC'] = True
|
||||
DEFINES['MOZ_NO_MOZALLOC'] = True
|
||||
|
||||
if CONFIG['OS_TARGET'] == 'Darwin':
|
||||
DEFINES['SIP_OS_OSX'] = True
|
||||
else:
|
||||
DEFINES['SIP_OS_LINUX'] = True
|
||||
Library('FuzzingSdp')
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'../..',
|
||||
'/media/mtransport',
|
||||
'/media/webrtc/signaling/src/common/browser_logging',
|
||||
]
|
||||
LOCAL_INCLUDES += [
|
||||
'/ipc/chromium/src',
|
||||
'/media/mtransport',
|
||||
'/media/webrtc/',
|
||||
'/media/webrtc/signaling/src/common/time_profiling',
|
||||
'/media/webrtc/signaling/src/peerconnection',
|
||||
]
|
||||
|
||||
USE_LIBS += [
|
||||
'/testing/gtest/gtest',
|
||||
'mozglue',
|
||||
'nspr',
|
||||
]
|
||||
SOURCES += [
|
||||
'sdp_parser_libfuzz.cpp',
|
||||
]
|
||||
|
||||
SOURCES = [
|
||||
'/media/webrtc/signaling/src/sdp/SdpAttribute.cpp',
|
||||
'/media/webrtc/signaling/src/sdp/SdpHelper.cpp',
|
||||
'/media/webrtc/signaling/src/sdp/SdpMediaSection.cpp',
|
||||
'/media/webrtc/signaling/src/sdp/sipcc/cpr_string.c',
|
||||
'/media/webrtc/signaling/src/sdp/sipcc/sdp_access.c',
|
||||
'/media/webrtc/signaling/src/sdp/sipcc/sdp_attr.c',
|
||||
'/media/webrtc/signaling/src/sdp/sipcc/sdp_attr_access.c',
|
||||
'/media/webrtc/signaling/src/sdp/sipcc/sdp_base64.c',
|
||||
'/media/webrtc/signaling/src/sdp/sipcc/sdp_config.c',
|
||||
'/media/webrtc/signaling/src/sdp/sipcc/sdp_main.c',
|
||||
'/media/webrtc/signaling/src/sdp/sipcc/sdp_services_unix.c',
|
||||
'/media/webrtc/signaling/src/sdp/sipcc/sdp_token.c',
|
||||
'/media/webrtc/signaling/src/sdp/sipcc/sdp_utils.c',
|
||||
'/media/webrtc/signaling/src/sdp/SipccSdp.cpp',
|
||||
'/media/webrtc/signaling/src/sdp/SipccSdpAttributeList.cpp',
|
||||
'/media/webrtc/signaling/src/sdp/SipccSdpMediaSection.cpp',
|
||||
'/media/webrtc/signaling/src/sdp/SipccSdpParser.cpp',
|
||||
'sdp_file_parser.cpp',
|
||||
]
|
||||
|
||||
Program('sdp_file_parser')
|
||||
FINAL_LIBRARY = 'xul-gtest'
|
||||
|
|
|
@ -1,119 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#define GTEST_HAS_RTTI 0
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "signaling/src/sdp/SipccSdpParser.h"
|
||||
|
||||
#include "CSFLog.h"
|
||||
|
||||
void CSFLog(CSFLogLevel priority, const char* sourceFile, int sourceLine, const char* tag , const char* format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
printf("%s\n:", tag);
|
||||
vprintf(format, ap);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void NS_DebugBreak(uint32_t aSeverity,
|
||||
const char* aStr, const char* aExpr,
|
||||
const char* aFile, int32_t aLine)
|
||||
{
|
||||
fprintf(stderr, "NS_DebugBreak: %u %s %s %s %u", aSeverity, aStr, aExpr,
|
||||
aFile, aLine);
|
||||
}
|
||||
} // end extern "C".
|
||||
|
||||
class PRLogModuleInfo;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
enum class LogLevel {
|
||||
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
void log_print(PRLogModuleInfo const* info, LogLevel level, char const* format, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
vprintf(format, ap);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
} // End namespace detail.
|
||||
|
||||
const std::string kDefaultFilename((char *)"/tmp/sdp.bin");
|
||||
std::string filename(kDefaultFilename);
|
||||
|
||||
class SdpParseTest : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
SdpParseTest() {}
|
||||
|
||||
void ParseSdp(const std::string &sdp) {
|
||||
mSdp = mParser.Parse(sdp);
|
||||
}
|
||||
|
||||
void SerializeSdp() {
|
||||
if (mSdp) {
|
||||
mSdp->Serialize(os);
|
||||
std::cout << "Serialized SDP:" << std::endl <<
|
||||
os.str() << std::endl;;
|
||||
}
|
||||
}
|
||||
|
||||
SipccSdpParser mParser;
|
||||
mozilla::UniquePtr<Sdp> mSdp;
|
||||
std::stringstream os;
|
||||
}; // class SdpParseTest
|
||||
|
||||
TEST_F(SdpParseTest, parseSdpFromFile)
|
||||
{
|
||||
std::ifstream file(filename.c_str(),
|
||||
std::ios::in|std::ios::binary|std::ios::ate);
|
||||
ASSERT_TRUE(file.is_open());
|
||||
std::streampos size = file.tellg();
|
||||
size_t nsize = size;
|
||||
nsize+=1;
|
||||
char *memblock = new char [nsize];
|
||||
memset(memblock, '\0', nsize);
|
||||
file.seekg(0, std::ios::beg);
|
||||
file.read(memblock, size);
|
||||
file.close();
|
||||
std::cout << "Read file " << filename << std::endl;
|
||||
ParseSdp(memblock);
|
||||
std::cout << "Parsed SDP" << std::endl;
|
||||
SerializeSdp();
|
||||
delete[] memblock;
|
||||
}
|
||||
|
||||
} // End namespace mozilla.
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
if (argc == 2) {
|
||||
mozilla::filename = argv[1];
|
||||
} else if (argc > 2) {
|
||||
std::cerr << "Usage: ./sdp_file_parser [filename]" << std::endl;
|
||||
return(1);
|
||||
}
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "FuzzingInterface.h"
|
||||
#include "LibFuzzerRegistry.h"
|
||||
|
||||
#include "signaling/src/sdp/SipccSdpParser.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
static mozilla::UniquePtr<Sdp> sdpPtr;
|
||||
static SipccSdpParser mParser;
|
||||
|
||||
int FuzzingInitSdpParser(int *argc, char ***argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
RunSdpParserFuzzing(const uint8_t* data, size_t size) {
|
||||
std::string message(reinterpret_cast<const char*>(data), size);
|
||||
|
||||
sdpPtr = mParser.Parse(message);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
MOZ_FUZZING_INTERFACE_RAW(FuzzingInitSdpParser, RunSdpParserFuzzing, SdpParser);
|
Загрузка…
Ссылка в новой задаче