From 3fee702ee271d3e7d3b1fa49e4614f2c45880527 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Mon, 4 Aug 2025 20:17:14 +0100 Subject: [PATCH] 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. --- sphaira/source/ui/menus/ftp_menu.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sphaira/source/ui/menus/ftp_menu.cpp b/sphaira/source/ui/menus/ftp_menu.cpp index fe14e02..888f08a 100644 --- a/sphaira/source/ui/menus/ftp_menu.cpp +++ b/sphaira/source/ui/menus/ftp_menu.cpp @@ -87,10 +87,13 @@ void Menu::Draw(NVGcontext* vg, Theme* theme) { NifmNetworkProfileData profile{}; if (R_SUCCEEDED(nifmGetCurrentNetworkProfile(&profile))) { 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("Passphrase:"_i18n, " %s", passphrase.c_str()); + draw("Passphrase:"_i18n, " %s", passphrase); } } }