Skip to content

Commit

Permalink
Merge pull request #1850 from 4m1g0/fixPSK
Browse files Browse the repository at this point in the history
Allow PSK instead of passphrase in WiFiSTA::begin
  • Loading branch information
igrr committed Apr 13, 2016
2 parents fa7e903 + a06ceb8 commit e82b74e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
return WL_CONNECT_FAILED;
}

if(passphrase && strlen(passphrase) > 63) {
if(passphrase && strlen(passphrase) > 64) {
// fail passphrase too long!
return WL_CONNECT_FAILED;
}
Expand All @@ -115,7 +115,10 @@ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase,
strcpy(reinterpret_cast<char*>(conf.ssid), ssid);

if(passphrase) {
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
if (strlen(passphrase) == 64) // it's not a passphrase, is the PSK
memcpy(reinterpret_cast<char*>(conf.password), passphrase, 64);
else
strcpy(reinterpret_cast<char*>(conf.password), passphrase);
} else {
*conf.password = 0;
}
Expand Down

2 comments on commit e82b74e

@karlp
Copy link
Contributor

@karlp karlp commented on e82b74e Dec 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bump from 63 to 64 is fine, but the extra code to do a memcpy instead of a strcpy, when you're already using strlen to determine the length, and the PSK is required to be ascii, is completely pointless and a needless complication.

@karlp
Copy link
Contributor

@karlp karlp commented on e82b74e Dec 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Further, using strlen to determine whether it's safe to use strcpy is completely _UN_safe)

Please sign in to comment.