1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

ArduinoOTA: don't crash on unrecognized packets (#4086)

* ArduinoOTA: handle end of packet in readStringUntil

fixes #3912

* ArduinoOTA: fix buffer overflow in parseInt

fixes #3912
This commit is contained in:
yoursunny 2018-01-03 22:14:32 -05:00 committed by Develo
parent 82e5186786
commit d9ef6b5f18

View File

@ -143,10 +143,10 @@ void ArduinoOTAClass::begin() {
int ArduinoOTAClass::parseInt(){ int ArduinoOTAClass::parseInt(){
char data[16]; char data[16];
uint8_t index = 0; uint8_t index;
char value; char value;
while(_udp_ota->peek() == ' ') _udp_ota->read(); while(_udp_ota->peek() == ' ') _udp_ota->read();
while(true){ for(index = 0; index < sizeof(data); ++index){
value = _udp_ota->peek(); value = _udp_ota->peek();
if(value < '0' || value > '9'){ if(value < '0' || value > '9'){
data[index++] = '\0'; data[index++] = '\0';
@ -159,13 +159,13 @@ int ArduinoOTAClass::parseInt(){
String ArduinoOTAClass::readStringUntil(char end){ String ArduinoOTAClass::readStringUntil(char end){
String res = ""; String res = "";
char value; int value;
while(true){ while(true){
value = _udp_ota->read(); value = _udp_ota->read();
if(value == '\0' || value == end){ if(value < 0 || value == '\0' || value == end){
return res; return res;
} }
res += value; res += static_cast<char>(value);
} }
return res; return res;
} }