WebsocketStompKit
WebsocketStompKit copied to clipboard
STOMPFrameFromData passing empty data causes crash
My server sent a message containing just a newline character in this form: @"\n" and this causes a crash in the STOMPFrameFromData
method. The error message was:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' *** First throw call stack: (0x18235822c 0x193e140e4 0x18223b4fc 0x1000b3f30 0x1000b8210 0x1000bd26c 0x1001d4fd4 0x1001d4f94 0x1001d9c28 0x18230f544 0x18230d5ec 0x182238f74 0x18bb536fc 0x186e3ad94 0x100058cc4 0x1944bea08) libc++abi.dylib: terminating with uncaught exception of type NSException
Coming from this line:
NSString *command = [[contents objectAtIndex:0] copy];
It seems that because the message is effectively empty, the entire contents array is removed, and then it obviously cannot access the object at index zero. A fix should be simple enough, it would just involve adding a check to see if the content array is empty when checking for a command and then returning something sensible from the method.
With some further investigation, I think this issue of a newline character being passed to the STOMPFrameFromData
is coming from the code checking for a heartbeat.
See issue #4