1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.
This commit is contained in:
Peter Zhu 2020-09-01 06:01:32 -04:00 committed by GitHub
parent a137874e67
commit 21ad4075a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2020-09-01 19:02:04 +09:00
Merged: https://github.com/ruby/ruby/pull/3487

Merged-By: nobu <nobu@ruby-lang.org>

2
gc.c
View file

@ -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: {