summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2020-09-01 06:01:32 -0400
committerGitHub <noreply@github.com>2020-09-01 19:01:32 +0900
commit21ad4075a71f302474a78dc744149ac8ce2ff0ec (patch)
treed4889e5d25b106d9a67a15ac65254d89d5bc32fb /gc.c
parenta137874e67b0b3f815be3ba322ed8925860bc673 (diff)
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3487 Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c2
1 files changed, 1 insertions, 1 deletions
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: {