From 15d3b7fe6dd421cc4ff77d106d17b0e9fd1ead45 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sat, 1 Oct 2022 16:14:59 +0900 Subject: Fix an out of bound access --- struct.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'struct.c') diff --git a/struct.c b/struct.c index a025d21af6..3a5dc8b7d4 100644 --- a/struct.c +++ b/struct.c @@ -1793,6 +1793,12 @@ rb_data_initialize_m(int argc, const VALUE *argv, VALUE self) VALUE members = struct_ivar_get(klass, id_members); size_t num_members = RARRAY_LEN(members); + if (argc == 0) { + if (num_members > 0) { + rb_exc_raise(rb_keyword_error_new("missing", members)); + } + return Qnil; + } if (argc > 1 || !RB_TYPE_P(argv[0], T_HASH)) { rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0)", argc); } -- cgit v1.2.1