aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2015-07-21 16:22:58 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2015-07-21 16:22:58 -0700
commit1c604fd4f54e0e5744a357818c1782ff7877844e (patch)
tree22b7a83a7ed42288492685f4b37bce7539e66b1c /src/core
parentc0a09015b17d8db1ea6bee0cba5d868c7f6f6fca (diff)
Fixed buggy grpc_compression_algorithm_parse
Diffstat (limited to 'src/core')
-rw-r--r--src/core/channel/compress_filter.c2
-rw-r--r--src/core/compression/algorithm.c8
-rw-r--r--src/core/surface/call.c9
3 files changed, 11 insertions, 8 deletions
diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c
index b41dcb92d9..9ff679df18 100644
--- a/src/core/channel/compress_filter.c
+++ b/src/core/channel/compress_filter.c
@@ -100,7 +100,7 @@ static grpc_mdelem* compression_md_filter(void *user_data, grpc_mdelem *md) {
if (md->key == channeld->mdstr_request_compression_algorithm_key) {
const char *md_c_str = grpc_mdstr_as_c_string(md->value);
- if (!grpc_compression_algorithm_parse(md_c_str,
+ if (!grpc_compression_algorithm_parse(md_c_str, strlen(md_c_str),
&calld->compression_algorithm)) {
gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s'. Ignoring.",
md_c_str);
diff --git a/src/core/compression/algorithm.c b/src/core/compression/algorithm.c
index 8a60b4ef48..077647ebe1 100644
--- a/src/core/compression/algorithm.c
+++ b/src/core/compression/algorithm.c
@@ -35,17 +35,17 @@
#include <string.h>
#include <grpc/compression.h>
-int grpc_compression_algorithm_parse(const char* name,
+int grpc_compression_algorithm_parse(const char* name, size_t name_length,
grpc_compression_algorithm *algorithm) {
/* we use strncmp not only because it's safer (even though in this case it
* doesn't matter, given that we are comparing against string literals, but
* because this way we needn't have "name" nil-terminated (useful for slice
* data, for example) */
- if (strncmp(name, "none", 4) == 0) {
+ if (strncmp(name, "none", name_length) == 0) {
*algorithm = GRPC_COMPRESS_NONE;
- } else if (strncmp(name, "gzip", 4) == 0) {
+ } else if (strncmp(name, "gzip", name_length) == 0) {
*algorithm = GRPC_COMPRESS_GZIP;
- } else if (strncmp(name, "deflate", 7) == 0) {
+ } else if (strncmp(name, "deflate", name_length) == 0) {
*algorithm = GRPC_COMPRESS_DEFLATE;
} else {
return 0;
diff --git a/src/core/surface/call.c b/src/core/surface/call.c
index bb1ed809f8..54f10261e3 100644
--- a/src/core/surface/call.c
+++ b/src/core/surface/call.c
@@ -495,7 +495,8 @@ static void set_encodings_accepted_by_peer(grpc_call *call,
for (i = 0; i < accept_encoding_parts.count; i++) {
const gpr_slice* slice = &accept_encoding_parts.slices[i];
if (grpc_compression_algorithm_parse(
- (const char *)GPR_SLICE_START_PTR(*slice), &algorithm)) {
+ (const char *)GPR_SLICE_START_PTR(*slice), GPR_SLICE_LENGTH(*slice),
+ &algorithm)) {
GPR_BITSET(&call->encodings_accepted_by_peer, algorithm);
} else {
/* TODO(dgq): it'd be nice to have a slice-to-cstr function to easily
@@ -1344,10 +1345,12 @@ static gpr_uint32 decode_compression(grpc_mdelem *md) {
grpc_compression_algorithm algorithm;
void *user_data = grpc_mdelem_get_user_data(md, destroy_compression);
if (user_data) {
- algorithm = ((grpc_compression_level)(gpr_intptr)user_data) - COMPRESS_OFFSET;
+ algorithm =
+ ((grpc_compression_level)(gpr_intptr)user_data) - COMPRESS_OFFSET;
} else {
const char *md_c_str = grpc_mdstr_as_c_string(md->value);
- if (!grpc_compression_algorithm_parse(md_c_str, &algorithm)) {
+ if (!grpc_compression_algorithm_parse(md_c_str, strlen(md_c_str),
+ &algorithm)) {
gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s'", md_c_str);
assert(0);
}