aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2016-01-06 11:48:15 -0800
committerGravatar murgatroid99 <mlumish@google.com>2016-01-06 11:48:15 -0800
commitc2ea3aec65a162f816d5ebc9d67b903ec6a34309 (patch)
treeea52a2704cfe73d79164be6b169c8754b02464ac
parent296ae72581f17438e9355d4862c3ad5c66d49807 (diff)
Parital implementation of ruby header checking
-rwxr-xr-xgrpc.gemspec2
-rw-r--r--src/ruby/ext/grpc/rb_call.c26
2 files changed, 17 insertions, 11 deletions
diff --git a/grpc.gemspec b/grpc.gemspec
index ee5c22c24c..006428f80a 100755
--- a/grpc.gemspec
+++ b/grpc.gemspec
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.add_dependency 'google-protobuf', '~> 3.0.0alpha.1.1'
- s.add_dependency 'googleauth', '~> 0.4'
+ s.add_dependency 'googleauth', '~> 0.5.1'
s.add_development_dependency 'bundler', '~> 1.9'
s.add_development_dependency 'logging', '~> 2.0'
diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c
index 1647d9b484..cbea76c3bf 100644
--- a/src/ruby/ext/grpc/rb_call.c
+++ b/src/ruby/ext/grpc/rb_call.c
@@ -311,6 +311,20 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) {
long array_length;
long i;
+ char *key_str;
+ if (TYPE(key) == T_SYMBOL) {
+ key_str = (char *)rb_id2name(SYM2ID(key));
+ } else { /* StringValueCStr does all other type exclusions for us */
+ key_str = StringValueCStr(key);
+ }
+
+ if (!grpc_header_key_is_legal(key_str)) {
+ rb_raise(rb_eArgError,
+ "'%s' is an invalid header key, must match [a-z0-9-_.]+",
+ key_str);
+ return ST_STOP;
+ }
+
/* Construct a metadata object from key and value and add it */
TypedData_Get_Struct(md_ary_obj, grpc_metadata_array,
&grpc_rb_md_ary_data_type, md_ary);
@@ -319,22 +333,14 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) {
/* If the value is an array, add capacity for each value in the array */
array_length = RARRAY_LEN(val);
for (i = 0; i < array_length; i++) {
- if (TYPE(key) == T_SYMBOL) {
- md_ary->metadata[md_ary->count].key = (char *)rb_id2name(SYM2ID(key));
- } else { /* StringValueCStr does all other type exclusions for us */
- md_ary->metadata[md_ary->count].key = StringValueCStr(key);
- }
+ md_ary->metadata[md_ary->count].key = key_str;
md_ary->metadata[md_ary->count].value = RSTRING_PTR(rb_ary_entry(val, i));
md_ary->metadata[md_ary->count].value_length =
RSTRING_LEN(rb_ary_entry(val, i));
md_ary->count += 1;
}
} else {
- if (TYPE(key) == T_SYMBOL) {
- md_ary->metadata[md_ary->count].key = (char *)rb_id2name(SYM2ID(key));
- } else { /* StringValueCStr does all other type exclusions for us */
- md_ary->metadata[md_ary->count].key = StringValueCStr(key);
- }
+ md_ary->metadata[md_ary->count].key = key_str;
md_ary->metadata[md_ary->count].value = RSTRING_PTR(val);
md_ary->metadata[md_ary->count].value_length = RSTRING_LEN(val);
md_ary->count += 1;