Bug#781504: Segmentation fault after pack ioctl unpack

2015-04-01 Thread Antonio Terceiro
On Mon, Mar 30, 2015 at 09:48:25AM +0200, Thomas Goirand wrote:
 Package: ruby2.1
 Version: 2.1.5-1
 Severity: grave
 Tags: patch
 
 Hi,
 
 When testing OpenStack Fuel, one of the components is using rethtool, which
 suffer from below ruby 2.1 upstream bug:
 
 https://bugs.ruby-lang.org/issues/10568
 
 The fix is attached in the above bug report, in this URL:
 https://bugs.ruby-lang.org/attachments/download/4936/ruby-2.1-rb-str-associated.patch
 
 I have also attached the patch.
 
 I tested to rebuilding the Ruby 2.1 interpreter using this patch, and this
 solved my issue.
 
 It would be super nice if this patch could land in Jessie before the release.
 This kind of crash IMO deserves such action. If you don't have time to patch
 the current Ruby 2.1 interpreter and would accept an NMU, let me know, and
 I will do so.

I have commented on the upstream bug saying that this still needed to be
applied to the 2.1 branch; I will wait 1-2 days to see if they apply,
otherwise I will include the patch in the Debian package and upload.

-- 
Antonio Terceiro terce...@debian.org


signature.asc
Description: Digital signature


Bug#781504: Segmentation fault after pack ioctl unpack

2015-03-30 Thread Thomas Goirand
Package: ruby2.1
Version: 2.1.5-1
Severity: grave
Tags: patch

Hi,

When testing OpenStack Fuel, one of the components is using rethtool, which
suffer from below ruby 2.1 upstream bug:

https://bugs.ruby-lang.org/issues/10568

The fix is attached in the above bug report, in this URL:
https://bugs.ruby-lang.org/attachments/download/4936/ruby-2.1-rb-str-associated.patch

I have also attached the patch.

I tested to rebuilding the Ruby 2.1 interpreter using this patch, and this
solved my issue.

It would be super nice if this patch could land in Jessie before the release.
This kind of crash IMO deserves such action. If you don't have time to patch
the current Ruby 2.1 interpreter and would accept an NMU, let me know, and
I will do so.

Cheers,

Thomas Goirand (zigo)
diff --git a/pack.c b/pack.c
index 71dd6af..6e515b2 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 +960,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) {
@@ -1801,7 +1840,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);
@@ -1810,7 +1849,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;
@@ -1844,7 +1883,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);
@@ -2006,4 +2045,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 3f0931b..38c1981 100644
--- a/test/ruby/test_pack.rb
+++ b/test/ruby/test_pack.rb
@@ -181,7 +181,7 @@ def test_pack_p
 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