From 88d62b47bfd960819fa88915648b54be3732dc2a Mon Sep 17 00:00:00 2001 From: Kevin Backhouse Date: Tue, 28 Jun 2022 13:43:51 +0100 Subject: [PATCH] Prevent the VALUEs in args from getting garbage collected too early (#7916) Prevent the VALUEs in args from getting garbage collected too early. --- projects/ruby/fuzz_ruby_gems.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/projects/ruby/fuzz_ruby_gems.c b/projects/ruby/fuzz_ruby_gems.c index 7f955b58b..0667f20ab 100644 --- a/projects/ruby/fuzz_ruby_gems.c +++ b/projects/ruby/fuzz_ruby_gems.c @@ -15,6 +15,10 @@ limitations under the License. #define ARRAYSIZE(x) (sizeof(x) / sizeof(x[0])) +// The maximum number of arguments of any of the target functions. +// Increase as needed. +#define MAX_NARGS 2 + enum RubyDataType { RDT_CString }; struct TargetFunction { @@ -143,12 +147,10 @@ int run_fuzz_function(struct ByteStream *bs, struct TargetFunction *fcn) { return -1; } - VALUE *args = calloc(fcn->nargs_, sizeof(VALUE)); - if (!args) { - return -1; - } + VALUE args[MAX_NARGS] = {}; int result = -1; int i; + assert(fcn->nargs_ <= MAX_NARGS); for (i = 0; i < fcn->nargs_; i++) { VALUE v = generate_value(bs, fcn->argTypes_[i]); if (!v) { @@ -166,7 +168,6 @@ int run_fuzz_function(struct ByteStream *bs, struct TargetFunction *fcn) { } out: - free(args); return result; }