Merge pull request #100 from jensh/mqtt_get_publish_data

mqtt_get_publish_data() should always return len=0 if data=NULL.
develop
Tuan PM 2016-06-30 07:49:00 +07:00 zatwierdzone przez GitHub
commit c082fcbd7c
1 zmienionych plików z 9 dodań i 8 usunięć

Wyświetl plik

@ -185,8 +185,10 @@ const char* ICACHE_FLASH_ATTR mqtt_get_publish_data(uint8_t* buffer, uint16_t* l
int i;
int totlen = 0;
int topiclen;
int blength = *length;
*length = 0;
for(i = 1; i < *length; ++i)
for(i = 1; i < blength; ++i)
{
totlen += (buffer[i] & 0x7f) << (7 * (i - 1));
if((buffer[i] & 0x80) == 0)
@ -197,20 +199,19 @@ const char* ICACHE_FLASH_ATTR mqtt_get_publish_data(uint8_t* buffer, uint16_t* l
}
totlen += i;
if(i + 2 >= *length)
if(i + 2 >= blength)
return NULL;
topiclen = buffer[i++] << 8;
topiclen |= buffer[i++];
if(i + topiclen >= *length){
*length = 0;
if(i + topiclen >= blength)
return NULL;
}
i += topiclen;
if(mqtt_get_qos(buffer) > 0)
{
if(i + 2 >= *length)
if(i + 2 >= blength)
return NULL;
i += 2;
}
@ -218,10 +219,10 @@ const char* ICACHE_FLASH_ATTR mqtt_get_publish_data(uint8_t* buffer, uint16_t* l
if(totlen < i)
return NULL;
if(totlen <= *length)
if(totlen <= blength)
*length = totlen - i;
else
*length = *length - i;
*length = blength - i;
return (const char*)(buffer + i);
}