diff options
| author | Peter Zhu <peter@peterzhu.ca> | 2025-09-10 14:47:06 -0400 |
|---|---|---|
| committer | Peter Zhu <peter@peterzhu.ca> | 2025-09-11 08:14:25 -0400 |
| commit | 21d76b423cf4967762dd783dd1114d980e33dac9 (patch) | |
| tree | db84c327d484c188a480f15a6a4934ed95049769 | |
| parent | 5a946a5be29a099ddaff55b52b5c2ab0cbe61ca1 (diff) | |
Fix out-of-bounds read in Method#inspect for unnamed parameters
For parameters without names, accessing the name in array index 1 would
be an out-of-bounds read.
| -rw-r--r-- | proc.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -3332,9 +3332,10 @@ method_inspect(VALUE method) for (int i = 0; i < RARRAY_LEN(params); i++) { pair = RARRAY_AREF(params, i); kind = RARRAY_AREF(pair, 0); - name = RARRAY_AREF(pair, 1); - // FIXME: in tests it turns out that kind, name = [:req] produces name to be false. Why?.. - if (NIL_P(name) || name == Qfalse) { + if (RARRAY_LEN(pair) > 1) { + name = RARRAY_AREF(pair, 1); + } + else { // FIXME: can it be reduced to switch/case? if (kind == req || kind == opt) { name = rb_str_new2("_"); @@ -3348,6 +3349,9 @@ method_inspect(VALUE method) else if (kind == nokey) { name = rb_str_new2("nil"); } + else { + name = Qnil; + } } if (kind == req) { |
