aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Kevin Backhouse <kevinbackhouse@github.com>2022-06-28 13:43:51 +0100
committerGravatar GitHub <noreply@github.com>2022-06-28 14:43:51 +0200
commit88d62b47bfd960819fa88915648b54be3732dc2a (patch)
tree18a6616a0e84fa7ce5c5df744e123e43297483c7
parentf78fb0a7e1729fedc2e4b0b2d7788c810dc1a94b (diff)
Prevent the VALUEs in args from getting garbage collected too early (#7916)
Prevent the VALUEs in args from getting garbage collected too early.
-rw-r--r--projects/ruby/fuzz_ruby_gems.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/projects/ruby/fuzz_ruby_gems.c b/projects/ruby/fuzz_ruby_gems.c
index 7f955b58..0667f20a 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;
}