Sha256: 21abacdee1043c7cf488876f41b9c85f1161f372e3a178b3d69bf94353685100

Contents?: true

Size: 968 Bytes

Versions: 2

Compression:

Stored size: 968 Bytes

Contents

#include <string>
#include <iostream>
#include <fstream>

#include <mruby.h>
#include <mruby/compile.h>

#include <src/libfuzzer/libfuzzer_macro.h>
#include <ruby.pb.h>
#include "proto_to_ruby.h"

using namespace ruby_fuzzer;
using namespace std;

int FuzzRB(const uint8_t *Data, size_t size) {
	mrb_value v;
	mrb_state *mrb = mrb_open();
	if (!mrb)
		return 0;

	char *code = (char *)malloc(size+1);
	if (!code)
		return 0;
	memcpy(code, Data, size);
	code[size] = '\0';

	if (const char *dump_path = getenv("PROTO_FUZZER_DUMP_PATH")) {
		// With libFuzzer binary run this to generate an RB file x.rb:
		// PROTO_FUZZER_DUMP_PATH=x.rb ./a.out proto-input
		std::ofstream of(dump_path);
		of.write(code, size);
	}
	v = mrb_load_string(mrb, code);
	mrb_close(mrb);

	free(code);
	return 0;
}

DEFINE_PROTO_FUZZER(const Function &function) {
	protoConverter converter;
	auto s = converter.FunctionToString(function);
	(void)FuzzRB((const uint8_t*)s.data(), s.size());
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
script_core-0.3.2 ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp
script_core-0.3.0 ext/enterprise_script_service/mruby/oss-fuzz/mruby_proto_fuzzer.cpp