From f9898b9ecab9851f32e1b3aad1176c801150f975 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 13 Sep 2023 09:14:20 -0400 Subject: [PATCH] [ruby/yarp] Better handle invalid gvar writes https://github.com/ruby/yarp/commit/eaaebc17c8 --- test/yarp/errors_test.rb | 6 ++++++ yarp/yarp.c | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/test/yarp/errors_test.rb b/test/yarp/errors_test.rb index e81a4cfac6..2a032e4f84 100644 --- a/test/yarp/errors_test.rb +++ b/test/yarp/errors_test.rb @@ -1143,6 +1143,12 @@ module YARP ] end + def test_invalid_global_variable_write + assert_errors expression("$',"), "$',", [ + ["Immutable variable as a write target", 0..2] + ] + end + private def assert_errors(expected, source, errors) diff --git a/yarp/yarp.c b/yarp/yarp.c index c7dcf482f7..78747682cb 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -8136,12 +8136,9 @@ parse_target(yp_parser_t *parser, yp_node_t *target) { target->type = YP_CONSTANT_TARGET_NODE; return target; case YP_BACK_REFERENCE_READ_NODE: - assert(sizeof(yp_global_variable_target_node_t) == sizeof(yp_back_reference_read_node_t)); - /* fallthrough */ case YP_NUMBERED_REFERENCE_READ_NODE: - assert(sizeof(yp_global_variable_target_node_t) == sizeof(yp_numbered_reference_read_node_t)); yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, YP_ERR_WRITE_TARGET_READONLY); - /* fallthrough */ + return target; case YP_GLOBAL_VARIABLE_READ_NODE: assert(sizeof(yp_global_variable_target_node_t) == sizeof(yp_global_variable_read_node_t)); target->type = YP_GLOBAL_VARIABLE_TARGET_NODE;