From 0d5d5c6932b3e04a7f5f57087d5215c3a2a3bbc5 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 12 Feb 2019 10:04:56 -0700 Subject: [PATCH] limit reason length --- .../src/Contacts/ContactDiscoveryService.m | 2 +- .../src/Network/API/Requests/OWSRequestFactory.m | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/SignalServiceKit/src/Contacts/ContactDiscoveryService.m b/SignalServiceKit/src/Contacts/ContactDiscoveryService.m index e34114488..cb373c9ed 100644 --- a/SignalServiceKit/src/Contacts/ContactDiscoveryService.m +++ b/SignalServiceKit/src/Contacts/ContactDiscoveryService.m @@ -406,7 +406,7 @@ NSError *ContactDiscoveryServiceErrorMakeWithReason(NSInteger code, NSString *re OWSAssertDebug(enclaveId.length > 0); if (![response isKindOfClass:[NSHTTPURLResponse class]]) { - OWSFailDebug(@"unexpected response type."); + *error = ContactDiscoveryServiceErrorMakeWithReason(ContactDiscoveryServiceErrorAssertionError, @"unexpected response type."); return nil; } NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; diff --git a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m index c9e394a96..1b0c08600 100644 --- a/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m +++ b/SignalServiceKit/src/Network/API/Requests/OWSRequestFactory.m @@ -498,7 +498,15 @@ NS_ASSUME_NONNULL_BEGIN if (reason == nil) { parameters = @{}; } else { - parameters = @{ @"reason": reason }; + const NSUInteger kServerReasonLimit = 1000; + NSString *limitedReason; + if (reason.length < kServerReasonLimit) { + limitedReason = reason; + } else { + OWSFailDebug(@"failure: reason should be under 1000"); + limitedReason = [reason substringToIndex:kServerReasonLimit - 1]; + } + parameters = @{ @"reason": limitedReason }; } NSString *path = [NSString stringWithFormat:@"/v1/directory/feedback-v2/%@", status]; return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"PUT" parameters:parameters];