Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25744] iOS: Fix http post data leak #43

Merged
merged 3 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions APSHTTPClient/APSHTTPPostForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
- (void)addFormData:(NSData *)data fileName:(NSString *)fileName fieldName:(NSString *)fieldName contentType:(NSString *)contentType;

- (void)addHeaderKey:(NSString *)key andHeaderValue:(NSString *)value;
- (void)destroyTemporaryData;

@end
15 changes: 15 additions & 0 deletions APSHTTPClient/APSHTTPPostForm.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ @implementation APSHTTPPostForm {
NSData *_stringData;
}

- (void)dealloc
{
[self destroyTemporaryData];
}

- (void)destroyTemporaryData
{
_requestFormDictionay = nil;
_requestFilesArray = nil;
_headers = nil;
_jsonData = nil;
_stringData = nil;
_postFormData = nil;
}

- (void)appendStringData:(NSString *)str
{
[[self postFormData] appendData:[str dataUsingEncoding:NSUTF8StringEncoding]];
Expand Down
4 changes: 4 additions & 0 deletions APSHTTPClient/APSHTTPRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ - (void)responseFinished
[self invokeCallbackWithState:APSHTTPCallbackStateDataStream];

[self invokeCallbackWithState:APSHTTPCallbackStateLoad];

[[self postForm] destroyTemporaryData];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be added in error block of
"- (void)URLSession:(nonnull NSURLSession *)session task:(nonnull NSURLSessionTask *)task didCompleteWithError:(nullable NSError *)error".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhh, it is already. But it should also be here to be used on successful POST requests. Or do you have objections there?

Copy link
Contributor

@vijaysingh-axway vijaysingh-axway Mar 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine here. But in following section also it should be there. Reason is function get return from error block, if error happens.

- (void)URLSession:(nonnull NSURLSession *)session task:(nonnull NSURLSessionTask *)task didCompleteWithError:(nullable NSError *)error
 {
   if (error != NULL) {
     DebugLog(@"%s", __PRETTY_FUNCTION__);
     self.response.readyState = APSHTTPResponseStateDone;
     [self invokeCallbackWithState:APSHTTPCallbackStateReadyState];
 
     self.response.connected = NO;
     self.response.error = error;
     [self invokeCallbackWithState:APSHTTPCallbackStateError];
     return;
   }

}

- (void)URLSession:(nonnull NSURLSession *)session task:(nonnull NSURLSessionTask *)task didCompleteWithError:(nullable NSError *)error
Expand All @@ -425,6 +427,7 @@ - (void)URLSession:(nonnull NSURLSession *)session task:(nonnull NSURLSessionTas
self.response.connected = NO;
self.response.error = error;
[self invokeCallbackWithState:APSHTTPCallbackStateError];
[[self postForm] destroyTemporaryData];
return;
}
DebugLog(@"%s", __PRETTY_FUNCTION__);
Expand All @@ -445,6 +448,7 @@ - (void)URLSession:(nonnull NSURLSession *)session didBecomeInvalidWithError:(nu
self.response.connected = NO;
self.response.error = error;
[self invokeCallbackWithState:APSHTTPCallbackStateError];
[[self postForm] destroyTemporaryData];
}

- (void)invokeCallbackWithState:(APSHTTPCallbackState)state
Expand Down