THRIFT-548. malloc our temporary buffer, rather than creating it on the stack.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@797175 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cocoa/src/protocol/TBinaryProtocol.m b/lib/cocoa/src/protocol/TBinaryProtocol.m
index ba7f462..5999e25 100644
--- a/lib/cocoa/src/protocol/TBinaryProtocol.m
+++ b/lib/cocoa/src/protocol/TBinaryProtocol.m
@@ -90,10 +90,18 @@
- (NSString *) readStringBody: (int) size
{
- char buff[size+1];
- [mTransport readAll: (uint8_t *) buff offset: 0 length: size];
- buff[size] = 0;
- return [NSString stringWithUTF8String: buff];
+ char * buffer = malloc(size+1);
+ if (!buffer) {
+ @throw [TProtocolException exceptionWithName: @"TProtocolException"
+ reason: [NSString stringWithFormat: @"Unable to allocate memory in %s, size: %i",
+ __PRETTY_FUNCTION__,
+ size]];;
+ }
+ [mTransport readAll: (uint8_t *) buffer offset: 0 length: size];
+ buffer[size] = 0;
+ NSString * result = [NSString stringWithUTF8String: buffer];
+ free(buffer);
+ return result;
}