From c51d8ff458e00b34e03b1fd5ac9bb0665c5a516a Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 24 Sep 2024 13:20:35 -0400 Subject: [PATCH] Fix undefined behavior in String#append_as_bytes The UNREACHABLE macro calls __builtin_unreachable, which according to the [GCC docs](https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005funreachable): > If control flow reaches the point of the __builtin_unreachable, the > program is undefined. But it can reach this point with the following script: "123".append_as_bytes("123") This can crash on some platforms with a `Trace/BPT trap: 5`. --- string.c | 1 + 1 file changed, 1 insertion(+) diff --git a/string.c b/string.c index 608d5cf7dc..dee17c86a6 100644 --- a/string.c +++ b/string.c @@ -3790,6 +3790,7 @@ rb_str_append_as_bytes(int argc, VALUE *argv, VALUE str) if (ENC_CODERANGE(obj) != ENC_CODERANGE_7BIT) { goto clear_cr; } + break; } default: UNREACHABLE;