ftp_menu: fix passphrase ascii convert which could cause a stack overflow.
from my notes: this converts the passphrase array into an ascii string well, turns out std::transform does not actually increase the std::string size when pushing the new ascii characters basically, std::string (normally) has small string optimisation. For this, they have a small array which it uses instead of allocating memory. std::transform casts the std::string itr to a void*. sooo it was basically manually writing to the class, which just so happened to be the SSO buffer. however after 32chars, it runs out...and starts overwriting the stack. so this was a stack overflow lmao only reason i found this is because i changed some optimisation flags, so the compiler ended up inlining std::transform, which detected the buffer overflow. and then i realised how fucked it was lol.
This commit is contained in:
@@ -87,10 +87,13 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) {
|
|||||||
NifmNetworkProfileData profile{};
|
NifmNetworkProfileData profile{};
|
||||||
if (R_SUCCEEDED(nifmGetCurrentNetworkProfile(&profile))) {
|
if (R_SUCCEEDED(nifmGetCurrentNetworkProfile(&profile))) {
|
||||||
const auto& settings = profile.wireless_setting_data;
|
const auto& settings = profile.wireless_setting_data;
|
||||||
std::string passphrase;
|
|
||||||
std::transform(std::cbegin(settings.passphrase), std::cend(settings.passphrase), passphrase.begin(), toascii);
|
// convert to ascii string.
|
||||||
|
char passphrase[sizeof(settings.passphrase) + 1]{};
|
||||||
|
std::transform(std::cbegin(settings.passphrase), std::cend(settings.passphrase), std::begin(passphrase), toascii);
|
||||||
|
|
||||||
draw("SSID:"_i18n, " %.*s", settings.ssid_len, settings.ssid);
|
draw("SSID:"_i18n, " %.*s", settings.ssid_len, settings.ssid);
|
||||||
draw("Passphrase:"_i18n, " %s", passphrase.c_str());
|
draw("Passphrase:"_i18n, " %s", passphrase);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user