From 21ad4075a71f302474a78dc744149ac8ce2ff0ec Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 1 Sep 2020 06:01:32 -0400 Subject: Don't read past the end of the Ruby string Ruby strings don't always have a null terminator, so we can't use it as a regular C string. By reading only the first len bytes of the Ruby string, we won't read past the end of the Ruby string. --- gc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gc.c b/gc.c index 102b618180..0e9ff2175e 100644 --- a/gc.c +++ b/gc.c @@ -11667,7 +11667,7 @@ rb_raw_obj_info(char *buff, const int buff_size, VALUE obj) } break; case T_STRING: { - APPENDF((BUFF_ARGS, "%s", RSTRING_PTR(obj))); + APPENDF((BUFF_ARGS, "%.*s", (int)RSTRING_LEN(obj), RSTRING_PTR(obj))); break; } case T_MOVED: { -- cgit v1.2.3