Skip to content
Snippets Groups Projects
Commit bbba491b authored by Jorge Canizales's avatar Jorge Canizales
Browse files

Reject non-ASCII text header values too.

parent 2529735d
No related branches found
No related tags found
No related merge requests found
...@@ -39,13 +39,13 @@ ...@@ -39,13 +39,13 @@
#import "NSDictionary+GRPC.h" #import "NSDictionary+GRPC.h"
// Used by the setter. // Used by the setter.
static void CheckKeyIsValid(NSString* key) { static void CheckIsNonNilASCII(NSString *name, NSString* value) {
if (!key) { if (!value) {
[NSException raise:NSInvalidArgumentException format:@"Key cannot be nil"]; [NSException raise:NSInvalidArgumentException format:@"%@ cannot be nil", name];
} }
if (![key canBeConvertedToEncoding:NSASCIIStringEncoding]) { if (![value canBeConvertedToEncoding:NSASCIIStringEncoding]) {
[NSException raise:NSInvalidArgumentException [NSException raise:NSInvalidArgumentException
format:@"Key %@ contains non-ASCII characters", key]; format:@"%@ %@ contains non-ASCII characters", name, value];
} }
} }
...@@ -63,6 +63,7 @@ static void CheckKeyValuePairIsValid(NSString *key, id value) { ...@@ -63,6 +63,7 @@ static void CheckKeyValuePairIsValid(NSString *key, id value) {
format:@"Expected NSString value for header %@ not ending in \"-bin\", " format:@"Expected NSString value for header %@ not ending in \"-bin\", "
@"instead got %@", key, value]; @"instead got %@", key, value];
} }
CheckIsNonNilASCII(@"Text header value", (NSString *)value);
} }
} }
...@@ -92,7 +93,7 @@ static void CheckKeyValuePairIsValid(NSString *key, id value) { ...@@ -92,7 +93,7 @@ static void CheckKeyValuePairIsValid(NSString *key, id value) {
- (void)setObject:(id)obj forKeyedSubscript:(NSString *)key { - (void)setObject:(id)obj forKeyedSubscript:(NSString *)key {
[self checkCallIsNotStarted]; [self checkCallIsNotStarted];
CheckKeyIsValid(key); CheckIsNonNilASCII(@"Header name", key);
key = key.lowercaseString; key = key.lowercaseString;
CheckKeyValuePairIsValid(key, obj); CheckKeyValuePairIsValid(key, obj);
_delegate[key] = obj; _delegate[key] = obj;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment