bportaluri / WiFiEsp

Arduino WiFi library for ESP8266 modules
GNU General Public License v3.0
550 stars 210 forks source link

WiFi.localIP() returns incorrect address (possible buffer overrun) #154

Open codeaholics opened 6 years ago

codeaholics commented 6 years ago

I have an ESP8266 connected to my home network. It has address 10.10.10.162. However, WiFi.localIP() reports 10.10.10.84. I enabled debug and ran the WPA connect example.

> getIpAddress
----------------------------------------------
>> AT+CIFSR
+CIFSR:STAIP,"10.10.10.162"
+CIFSR:STAMAC,"84:f3:eb:94:be:98"

OK
---------------------------------------------- > 10.10.10.1620D:8B

IP Address: 10.10.10.84

Here, you can see the board reporting the right IP address, but then the buffer that's read into appears to include some garbage at the end which messes up the parsing.

Note that 1620 (the digits after the third . in the corrupt buffer) is 0x654. Mask that with 0xFF and you get 0x54 = 84 -> the incorrectly returned answer. So it seems like the code is parsing as many digits as it can, then masking it to report the IP address. This would work (although the masking would be unnecessary) if the buffer weren't corrupted.

me-bad-dev commented 5 years ago

Same issue here.. I think its because array initialized in functions are not zeroed out. For me zero-ing the 'buf' array worked so far. If anyone wants to try: image