File 0007-Fix-segmentation-fault-after-pack-ioctl-unpack.patch of Package ruby2.1
From 681e4d0f5716599e6daa3b917b12f3d93634ce0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcus=20R=C3=BCckert?= <mrueckert@suse.de>
Date: Tue, 7 Mar 2017 14:13:09 +0100
Subject: [PATCH 07/13] Fix segmentation fault after pack & ioctl & unpack
bug#10568
boo#909695
---
pack.c | 35 +++++++++++++++++++++++++++++++----
test/ruby/test_pack.rb | 2 +-
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/pack.c b/pack.c
index 400e85c8cc..f58e66d564 100644
--- a/pack.c
+++ b/pack.c
@@ -234,6 +234,31 @@ static void qpencode(VALUE,VALUE,long);
static unsigned long utf8_to_uv(const char*,long*);
+static ID id_associated;
+
+static void
+str_associate(VALUE str, VALUE add)
+{
+ VALUE assoc;
+
+ assoc = rb_attr_get(str, id_associated);
+ if (RB_TYPE_P(assoc, T_ARRAY)) {
+ /* already associated */
+ rb_ary_concat(assoc, add);
+ }
+ else {
+ rb_ivar_set(str, id_associated, add);
+ }
+}
+
+static VALUE
+str_associated(VALUE str)
+{
+ VALUE assoc = rb_attr_get(str, id_associated);
+ if (NIL_P(assoc)) assoc = Qfalse;
+ return assoc;
+}
+
/*
* call-seq:
* arr.pack ( aTemplateString ) -> aBinaryString
@@ -921,7 +946,7 @@ pack_pack(VALUE ary, VALUE fmt)
}
if (associates) {
- rb_str_associate(res, associates);
+ str_associate(res, associates);
}
OBJ_INFECT(res, fmt);
switch (enc_info) {
@@ -1803,7 +1828,7 @@ pack_unpack(VALUE str, VALUE fmt)
VALUE a;
const VALUE *p, *pend;
- if (!(a = rb_str_associated(str))) {
+ if (!(a = str_associated(str))) {
rb_raise(rb_eArgError, "no associated pointer");
}
p = RARRAY_CONST_PTR(a);
@@ -1812,7 +1837,7 @@ pack_unpack(VALUE str, VALUE fmt)
if (RB_TYPE_P(*p, T_STRING) && RSTRING_PTR(*p) == t) {
if (len < RSTRING_LEN(*p)) {
tmp = rb_tainted_str_new(t, len);
- rb_str_associate(tmp, a);
+ str_associate(tmp, a);
}
else {
tmp = *p;
@@ -1846,7 +1871,7 @@ pack_unpack(VALUE str, VALUE fmt)
VALUE a;
const VALUE *p, *pend;
- if (!(a = rb_str_associated(str))) {
+ if (!(a = str_associated(str))) {
rb_raise(rb_eArgError, "no associated pointer");
}
p = RARRAY_CONST_PTR(a);
@@ -2008,4 +2033,6 @@ Init_pack(void)
{
rb_define_method(rb_cArray, "pack", pack_pack, 1);
rb_define_method(rb_cString, "unpack", pack_unpack, 1);
+
+ id_associated = rb_intern_const("__pack_associated__");
}
diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb
index 4b089f7322..64d1e68245 100644
--- a/test/ruby/test_pack.rb
+++ b/test/ruby/test_pack.rb
@@ -181,7 +181,7 @@ class TestPack < Test::Unit::TestCase
assert_equal a[0], a.pack("p").unpack("p")[0]
assert_equal a, a.pack("p").freeze.unpack("p*")
assert_raise(ArgumentError) { (a.pack("p") + "").unpack("p*") }
- assert_raise(ArgumentError) { (a.pack("p") << "d").unpack("p*") }
+ assert_equal a, (a.pack("p") << "d").unpack("p*")
end
def test_format_string_modified
--
2.12.0