krsna4u / skpsmtpmessage

Automatically exported from code.google.com/p/skpsmtpmessage
0 stars 0 forks source link

Crash in - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode #53

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
There is a segment of code that's incorrect here that can cause crashes:

- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode 
{
    switch(eventCode) 
    {
        case NSStreamEventHasBytesAvailable:
        {
            uint8_t buf[1024];
            memset(buf, 0, sizeof(uint8_t) * 1024);
            unsigned int len = 0;
            len = [(NSInputStream *)stream read:buf maxLength:1024];
            if(len) {

The documentation for read:maxLength: says it can return a negative number on 
failure. So len should be signed, and the if statement modified:

- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode 
{
    switch(eventCode) 
    {
        case NSStreamEventHasBytesAvailable:
        {
            uint8_t buf[1024];
            memset(buf, 0, sizeof(uint8_t) * 1024);
            NSInteger len = 0;
            len = [(NSInputStream *)stream read:buf maxLength:1024];
            if(len > 0) 

Original issue reported on code.google.com by guardian...@gmail.com on 30 Jun 2011 at 2:16