Skip to content

Commit d25915d

Browse files
yoursunnyincowizglenlee
authored andcommitted
ArduinoOTA: don't crash on unrecognized packets (esp8266#4086)
* ArduinoOTA: handle end of packet in readStringUntil fixes esp8266#3912 * ArduinoOTA: fix buffer overflow in parseInt fixes esp8266#3912
1 parent 209ad72 commit d25915d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

libraries/ArduinoOTA/ArduinoOTA.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ void ArduinoOTAClass::begin() {
143143

144144
int ArduinoOTAClass::parseInt(){
145145
char data[16];
146-
uint8_t index = 0;
146+
uint8_t index;
147147
char value;
148148
while(_udp_ota->peek() == ' ') _udp_ota->read();
149-
while(true){
149+
for(index = 0; index < sizeof(data); ++index){
150150
value = _udp_ota->peek();
151151
if(value < '0' || value > '9'){
152152
data[index++] = '\0';
@@ -159,13 +159,13 @@ int ArduinoOTAClass::parseInt(){
159159

160160
String ArduinoOTAClass::readStringUntil(char end){
161161
String res = "";
162-
char value;
162+
int value;
163163
while(true){
164164
value = _udp_ota->read();
165-
if(value == '\0' || value == end){
165+
if(value < 0 || value == '\0' || value == end){
166166
return res;
167167
}
168-
res += value;
168+
res += static_cast<char>(value);
169169
}
170170
return res;
171171
}

0 commit comments

Comments
 (0)