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`
pull/5528/head
Rafael Sales 9 years ago
parent 6a36274757
commit ac491d8c1f
  1. 6
      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;

Loading…
Cancel
Save