Skip to content
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

ESP8266WiFiScan does not terminate a 32 character long SSID #2200

Closed
liquidfalcon opened this issue Jun 27, 2016 · 3 comments
Closed

ESP8266WiFiScan does not terminate a 32 character long SSID #2200

liquidfalcon opened this issue Jun 27, 2016 · 3 comments
Assignees
Labels
component: libraries type: bug waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Milestone

Comments

@liquidfalcon
Copy link

ESP8266WiFiScan's ssid(uint8_t i) function assumes bss_info's ssid member is null terminated with the following statement:

return String(reinterpret_cast<const char*>(it->ssid));

Now, this works fine for any SSID less than 32 characters, as bss_info will have at least one null byte at the end. In the event that an SSID is exactly 32 characters, bss_info->ssid will not be null terminated, and the above line will include garbage in the String as it tries to find a null byte beyond the member.

A memcpy of 32 bytes like below guarantees at most 32 characters are read and correctly terminated, and seems to work fine during my testing.

char ssidBuffer[33] = {0};
memcpy(&ssidBufer[0], it->ssid, 32); 
return String(ssidBuffer);
@devyte
Copy link
Collaborator

devyte commented Oct 16, 2017

@liquidfalcon the SDK uses uint8 ssid[32] for storing the SSIDs, and this is pretty much across the board, not just for the scanning. You mentioned testing. Do you mean that 32-char SSIDs work correctly? If so, then the implication is that the SDK doesn't use null-terminated strings to represent SSIDs. This is an important bit of information, as your code may be needed in all places where the ssids are obtained, including the station and softap ones.
Then, there is also the 64-char password.

@devyte
Copy link
Collaborator

devyte commented Jan 8, 2018

@liquidfalcon can you confirm that SSIDs with 32 chars work work correctly with your change?

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Jan 8, 2018
@devyte devyte added this to the 2.5.0 milestone Jan 8, 2018
@devyte devyte self-assigned this Jan 8, 2018
@jgesser
Copy link

jgesser commented Apr 27, 2018

I had the same problem and submitted a PR to fix it: #4691
It worked for me in both scan and connect to a SSID with exact 32 bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: libraries type: bug waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

4 participants