From: Bryan Duxbury Date: Mon, 24 Oct 2011 17:29:16 +0000 (+0000) Subject: THRIFT-1400. rb: Ruby native extension aborts with __stack_chk_fail in OSX X-Git-Tag: 0.8.0~45 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=bcbf6d6fcda19768ab526e4dd15422584e9db79e;p=common%2Fthrift.git THRIFT-1400. rb: Ruby native extension aborts with __stack_chk_fail in OSX git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1188248 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/rb/ext/struct.c b/lib/rb/ext/struct.c index 590983f3..82345730 100644 --- a/lib/rb/ext/struct.c +++ b/lib/rb/ext/struct.c @@ -231,10 +231,10 @@ static VALUE rb_thrift_struct_write(VALUE self, VALUE protocol); static void write_anything(int ttype, VALUE value, VALUE protocol, VALUE field_info); VALUE get_field_value(VALUE obj, VALUE field_name) { - char name_buf[RSTRING_LEN(field_name) + 1]; + char name_buf[RSTRING_LEN(field_name) + 2]; name_buf[0] = '@'; - strlcpy(&name_buf[1], RSTRING_PTR(field_name), sizeof(name_buf)); + strlcpy(&name_buf[1], RSTRING_PTR(field_name), RSTRING_LEN(field_name) + 1); VALUE value = rb_ivar_get(obj, rb_intern(name_buf)); @@ -417,10 +417,10 @@ static void skip_map_contents(VALUE protocol, VALUE key_type_value, VALUE value_ static void skip_list_or_set_contents(VALUE protocol, VALUE element_type_value, int size); static void set_field_value(VALUE obj, VALUE field_name, VALUE value) { - char name_buf[RSTRING_LEN(field_name) + 1]; + char name_buf[RSTRING_LEN(field_name) + 2]; name_buf[0] = '@'; - strlcpy(&name_buf[1], RSTRING_PTR(field_name), sizeof(name_buf)); + strlcpy(&name_buf[1], RSTRING_PTR(field_name), RSTRING_LEN(field_name)+1); rb_ivar_set(obj, rb_intern(name_buf), value); }