Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
56fada5d
Commit
56fada5d
authored
9 years ago
by
murgatroid99
Browse files
Options
Downloads
Patches
Plain Diff
Make the Ruby extension throw an error when passed invalid metadata
parent
c9d3084b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ruby/ext/grpc/rb_call.c
+31
-9
31 additions, 9 deletions
src/ruby/ext/grpc/rb_call.c
templates/grpc.gemspec.template
+1
-1
1 addition, 1 deletion
templates/grpc.gemspec.template
with
32 additions
and
10 deletions
src/ruby/ext/grpc/rb_call.c
+
31
−
9
View file @
56fada5d
/*
*
* Copyright 2015, Google Inc.
* Copyright 2015
-2016
, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
...
...
@@ -310,15 +310,20 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) {
grpc_metadata_array
*
md_ary
=
NULL
;
long
array_length
;
long
i
;
char
*
key_str
;
size_t
key_len
;
char
*
value_str
;
size_t
value_len
;
if
(
TYPE
(
key
)
==
T_SYMBOL
)
{
key_str
=
(
char
*
)
rb_id2name
(
SYM2ID
(
key
));
key_len
=
strlen
(
key_str
);
}
else
{
/* StringValueCStr does all other type exclusions for us */
key_str
=
StringValueCStr
(
key
);
key_len
=
RSTRING_LEN
(
key
);
}
if
(
!
grpc_header_key_is_legal
(
key_str
))
{
if
(
!
grpc_header_key_is_legal
(
key_str
,
key_len
))
{
rb_raise
(
rb_eArgError
,
"'%s' is an invalid header key, must match [a-z0-9-_.]+"
,
key_str
);
...
...
@@ -330,19 +335,36 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) {
&
grpc_rb_md_ary_data_type
,
md_ary
);
if
(
TYPE
(
val
)
==
T_ARRAY
)
{
/* If the value is an array, add capacity for each value in the array */
array_length
=
RARRAY_LEN
(
val
);
/* If the value is an array, add capacity for each value in the array */
for
(
i
=
0
;
i
<
array_length
;
i
++
)
{
value_str
=
RSTRING_PTR
(
rb_ary_entry
(
val
,
i
));
value_len
=
RSTRING_LEN
(
rb_ary_entry
(
val
,
i
));
if
(
!
grpc_is_binary_header
(
key_str
,
key_len
)
&&
!
grpc_header_nonbin_value_is_legal
(
value_str
,
value_len
))
{
// The value has invalid characters
rb_raise
(
rb_eArgError
,
"Header value '%s' has invalid characters"
,
value_str
);
return
ST_STOP
;
}
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
->
metadata
[
md_ary
->
count
].
value
=
value_str
;
md_ary
->
metadata
[
md_ary
->
count
].
value_length
=
value_len
;
md_ary
->
count
+=
1
;
}
}
else
{
value_str
=
RSTRING_PTR
(
val
);
value_len
=
RSTRING_LEN
(
val
);
if
(
!
grpc_is_binary_header
(
key_str
,
key_len
)
&&
!
grpc_header_nonbin_value_is_legal
(
value_str
,
value_len
))
{
// The value has invalid characters
rb_raise
(
rb_eArgError
,
"Header value '%s' has invalid characters"
,
value_str
);
return
ST_STOP
;
}
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
->
metadata
[
md_ary
->
count
].
value
=
value_str
;
md_ary
->
metadata
[
md_ary
->
count
].
value_length
=
value_len
;
md_ary
->
count
+=
1
;
}
...
...
This diff is collapsed.
Click to expand it.
templates/grpc.gemspec.template
+
1
−
1
View file @
56fada5d
...
...
@@ -35,7 +35,7 @@
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'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment