Skip to content

Commit

Permalink
IPC fuzzer: move mutate.cc and generate.cc into ipc_fuzzer namespace
Browse files Browse the repository at this point in the history
BUG=260848
TBR=kalman@chromium.org

Review URL: https://codereview.chromium.org/143893018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@246472 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
aedla@chromium.org committed Jan 23, 2014
1 parent bc14867 commit d1c15d6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
6 changes: 4 additions & 2 deletions chrome/common/extensions/permissions/socket_permission_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include "extensions/common/permissions/api_permission.h"
#include "ipc/ipc_param_traits.h"

namespace ipc_fuzzer {
template <class T> struct FuzzTraits;
template <class T> struct GenerateTraits;
} // namespace ipc_fuzzer

namespace extensions {

Expand Down Expand Up @@ -67,8 +69,8 @@ class SocketPermissionData {
private:
// Friend so ParamTraits can serialize us.
friend struct IPC::ParamTraits<SocketPermissionData>;
friend struct FuzzTraits<SocketPermissionData>;
friend struct GenerateTraits<SocketPermissionData>;
friend struct ipc_fuzzer::FuzzTraits<SocketPermissionData>;
friend struct ipc_fuzzer::GenerateTraits<SocketPermissionData>;

SocketPermissionEntry& entry();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include "content/public/common/socket_permission_request.h"
#include "ipc/ipc_param_traits.h"

namespace ipc_fuzzer {
template <class T> struct FuzzTraits;
template <class T> struct GenerateTraits;
} // namespace ipc_fuzzer

namespace extensions {

Expand Down Expand Up @@ -69,8 +71,8 @@ class SocketPermissionEntry {
private:
// Friend so ParamTraits can serialize us.
friend struct IPC::ParamTraits<SocketPermissionEntry>;
friend struct FuzzTraits<SocketPermissionEntry>;
friend struct GenerateTraits<SocketPermissionEntry>;
friend struct ipc_fuzzer::FuzzTraits<SocketPermissionEntry>;
friend struct ipc_fuzzer::GenerateTraits<SocketPermissionEntry>;

// The permission type, host and port.
content::SocketPermissionRequest pattern_;
Expand Down
20 changes: 11 additions & 9 deletions tools/ipc_fuzzer/mutate/generate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace IPC {
class Message;
} // namespace IPC

namespace ipc_fuzzer {

// Interface implemented by those who generate basic types. The types all
// correspond to the types which a pickle from base/pickle.h can pickle,
// plus the floating point types.
Expand All @@ -57,8 +59,6 @@ class Generator {
virtual void GenerateBytes(void* data, int data_len) = 0;
};

namespace {

template <typename T>
void GenerateIntegralType(T* value) {
*value = static_cast<T>(base::RandUint64());
Expand All @@ -78,8 +78,6 @@ void GenerateStringType(T* value) {
*value = temp_string;
}

} // namespace

class GeneratorImpl : public Generator {
public:
GeneratorImpl() {}
Expand Down Expand Up @@ -769,7 +767,7 @@ void PopulateGeneratorFunctionVector(
static const char kCountSwitch[] = "count";
static const char kHelpSwitch[] = "help";

int main(int argc, char** argv) {
int GenerateMain(int argc, char** argv) {
CommandLine::Init(argc, argv);
CommandLine* cmd = CommandLine::ForCurrentProcess();
CommandLine::StringVector args = cmd->GetArgs();
Expand All @@ -790,7 +788,7 @@ int main(int argc, char** argv) {
<< " distinct messages present in chrome.\n";

Generator* generator = new GeneratorImpl();
ipc_fuzzer::MessageVector message_vector;
MessageVector message_vector;

int bad_count = 0;
if (message_count < 0) {
Expand All @@ -814,10 +812,14 @@ int main(int argc, char** argv) {

std::cerr << "Failed to generate " << bad_count << " messages.\n";

if (!ipc_fuzzer::MessageFile::Write(
base::FilePath(output_file_name), message_vector)) {
if (!MessageFile::Write(base::FilePath(output_file_name), message_vector))
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}

} // namespace ipc_fuzzer

int main(int argc, char** argv) {
return ipc_fuzzer::GenerateMain(argc, argv);
}
22 changes: 12 additions & 10 deletions tools/ipc_fuzzer/mutate/mutate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ namespace IPC {
class Message;
} // namespace IPC

namespace ipc_fuzzer {

// Interface implemented by those who fuzz basic types. The types all
// correspond to the types which a pickle from base/pickle.h can pickle,
// plus the floating point types.
Expand All @@ -58,8 +60,6 @@ class Fuzzer {
virtual void FuzzBytes(void* data, int data_len) = 0;
};

namespace {

template <typename T>
void FuzzIntegralType(T* value, unsigned int frequency) {
if (base::RandInt(0, frequency) == 0) {
Expand All @@ -86,8 +86,6 @@ void FuzzStringType(T* value, unsigned int frequency,
}
}

} // namespace

// One such fuzzer implementation.
class DefaultFuzzer : public Fuzzer {
public:
Expand Down Expand Up @@ -656,7 +654,7 @@ void usage() {

} // namespace

int main(int argc, char** argv) {
int MutateMain(int argc, char** argv) {
CommandLine::Init(argc, argv);
CommandLine* cmd = CommandLine::ForCurrentProcess();
CommandLine::StringVector args = cmd->GetArgs();
Expand Down Expand Up @@ -694,8 +692,8 @@ int main(int argc, char** argv) {
FuzzFunctionMap fuzz_function_map;
PopulateFuzzFunctionMap(&fuzz_function_map);

ipc_fuzzer::MessageVector message_vector;
if (!ipc_fuzzer::MessageFile::Read(
MessageVector message_vector;
if (!MessageFile::Read(
base::FilePath(input_file_name), &message_vector)) {
return EXIT_FAILURE;
}
Expand All @@ -716,10 +714,14 @@ int main(int argc, char** argv) {
if (permute)
std::random_shuffle(message_vector.begin(), message_vector.end());

if (!ipc_fuzzer::MessageFile::Write(
base::FilePath(output_file_name), message_vector)) {
if (!MessageFile::Write(base::FilePath(output_file_name), message_vector))
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}

} // namespace ipc_fuzzer

int main(int argc, char** argv) {
return ipc_fuzzer::MutateMain(argc, argv);
}

0 comments on commit d1c15d6

Please sign in to comment.