[前][次][番号順一覧][スレッド一覧]

ruby-changes:62789

From: Peter <ko1@a...>
Date: Tue, 1 Sep 2020 19:02:00 +0900 (JST)
Subject: [ruby-changes:62789] 21ad4075a7 (master): Don't read past the end of the Ruby string

https://git.ruby-lang.org/ruby.git/commit/?id=21ad4075a7

From 21ad4075a71f302474a78dc744149ac8ce2ff0ec Mon Sep 17 00:00:00 2001
From: Peter Zhu <peter@p...>
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.

diff --git a/gc.c b/gc.c
index 102b618..0e9ff21 100644
--- a/gc.c
+++ b/gc.c
@@ -11667,7 +11667,7 @@ rb_raw_obj_info(char *buff, const int buff_size, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L11667
             }
 	    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 v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]