diff options
author | Rafael Sales <rafaelcds@gmail.com> | 2016-03-02 02:30:29 -0300 |
---|---|---|
committer | Rafael Sales <rafaelcds@gmail.com> | 2016-03-31 19:35:20 -0300 |
commit | ac491d8c1f901fd44c613301d247cd1cd6b82d72 (patch) | |
tree | f9ba270519c45bcc1ac973309a4c765aca5a4d15 | |
parent | 6a362747571b6a47c3a84c8e2df25814230a53a7 (diff) |
Raise on unexpected metadata values
The existing implementation was causing segmentation fault because
src/ruby/ext/grpc/rb_call.c:358 was trying to convert any value type other than
Array to String. The Array type is handled in first `if`. This change will cause
the Ruby code that sends non-string values to fail with a better message:
`ArgumentError: Header values must be of type string or array`
-rw-r--r-- | src/ruby/ext/grpc/rb_call.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c index dc80d18b45..f5fdbb2ffd 100644 --- a/src/ruby/ext/grpc/rb_call.c +++ b/src/ruby/ext/grpc/rb_call.c @@ -359,7 +359,7 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) { md_ary->metadata[md_ary->count].value_length = value_len; md_ary->count += 1; } - } else { + } else if (TYPE(val) == T_STRING) { value_str = RSTRING_PTR(val); value_len = RSTRING_LEN(val); if (!grpc_is_binary_header(key_str, key_len) && @@ -373,6 +373,10 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) { md_ary->metadata[md_ary->count].value = value_str; md_ary->metadata[md_ary->count].value_length = value_len; md_ary->count += 1; + } else { + rb_raise(rb_eArgError, + "Header values must be of type string or array"); + return ST_STOP; } return ST_CONTINUE; |