-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Possible buffer overflow in WiFi scan results #5853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
PS, the sketch was created from the example code at https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-class.html |
I bumped in this issue several days ago. May be the problem occurs during the reading from the ssid or WiFi.SSID(i) because several times happened to me, that the first or first two rows returned correct value but the next one not: Serial.println(WiFi.SSID(i)); I hope it could help to find the error. |
From the behavior this isn't a buffer overflow, it's an unterminated C string. Seems like the ROM is doing a
Needs to be updated to copy the 32-chars in the bss struct and 0-terminate it locally before assigning to the returned String. |
I just noticed a similar commit/bugfix mentioned while browsing through this list: #5873 So let's hope not too much time will be lost here if it is also fixed in the SDK 2.2.2 |
Yes, it is. But the max length of an SSID is 32 characters and this one is that. Hence the reason to see it as a (potential) problem. In any way, seeing strange characters like this should never be ignored since it means there is a problem and could involve memory corruption or buffer overflows. |
I've just pushed a PR that should 0-terminate any 32 byte long SSIDs. I can't make one that long on my router, though, so can't test it myself. Logically, the patch is straightforward, though (famous last words). @adrionics can you give PR #5889 a test since you seem to have a 32byte long SSID? |
earlephilhower, that does indeed fix it. Would there be any other situations that use the it->ssid property expecting it to be null terminated? Also, would it be better to do the following (using the sizeof(it->ssid) to set the null caracter):
instead of
|
I noticed a strange output when scanning networks and outputting the list. It happens when there is a network present with an SSID of 32 characters long (the maximum SSID length).
The output of the included MCVE sketch is below - note item 6 with three strange characters before the comma:
Sketch:
Since this looks like a buffer overflow, I thought it was important to point it out!
The text was updated successfully, but these errors were encountered: