From 24dc9891be7e97ca351c58bce00c488f5ba7b398 Mon Sep 17 00:00:00 2001 From: shenyining Date: Thu, 21 Mar 2019 20:11:44 +0800 Subject: [PATCH] fix CVE-2018-16396 patch url: https://github.com/ruby/ruby/commit/4989bad4387ee2e9a7309d51840bc0705a248460 CVE: https://nvd.nist.gov/vuln/detail/CVE-2018-16396 https://www.ruby-lang.org/en/news/2018/10/17/not-propagated-taint-flag-in-some-formats-of-pack-cve-2018-16396/ Signed-off-by: shenyining --- pack.c | 7 +++++++ test/ruby/test_pack.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/pack.c b/pack.c index 11d26bd..50f3dce 100644 --- a/pack.c +++ b/pack.c @@ -749,6 +749,7 @@ pack_pack(int argc, VALUE *argv, VALUE ary) StringValue(from); ptr = RSTRING_PTR(from); plen = RSTRING_LEN(from); + OBJ_INFECT(res, from); if (len == 0 && type == 'm') { encodes(res, ptr, plen, type, 0); @@ -776,6 +777,7 @@ pack_pack(int argc, VALUE *argv, VALUE ary) case 'M': /* quoted-printable encoded string */ from = rb_obj_as_string(NEXTFROM); + OBJ_INFECT(res, from); if (len <= 1) len = 72; qpencode(res, from, len); @@ -801,6 +803,7 @@ pack_pack(int argc, VALUE *argv, VALUE ary) } else { t = StringValuePtr(from); + OBJ_INFECT(res, from); rb_obj_taint(from); } if (!associates) { @@ -1184,6 +1187,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, int mode) len = (send - s) * 8; bits = 0; bitstr = rb_usascii_str_new(0, len); + OBJ_INFECT(bitstr, str); t = RSTRING_PTR(bitstr); for (i=0; i>= 1; @@ -1205,6 +1209,7 @@ pack_unpack_internal(VALUE str, VALUE fmt, int mode) len = (send - s) * 8; bits = 0; bitstr = rb_usascii_str_new(0, len); + OBJ_INFECT(bitstr, str); t = RSTRING_PTR(bitstr); for (i=0; i