Don't crash on malformed input when configuring a remote library.

This commit is contained in:
casey langen 2020-10-23 11:01:54 -07:00
parent c6f7faa3cb
commit 001afe6e9a
2 changed files with 13 additions and 4 deletions

View File

@ -54,7 +54,16 @@ using namespace cursespp;
#define R(x) (x->GetX() + x->GetWidth())
static const std::string kArrowSymbol = "> ";
constexpr const char* kArrowSymbol = "> ";
static int getIntFromTextInput(TextInput& input, int defaultValue = -1) {
try {
return std::stoi(input.GetText());
}
catch (...) {
return defaultValue;
}
}
static inline int longestStringLength(const std::vector<std::string>&& keys) {
int max = 0;
@ -228,8 +237,8 @@ void RemoteLibrarySettingsLayout::SyncPreferencesAndLayout() {
void RemoteLibrarySettingsLayout::SavePreferences() {
auto host = this->hostInput->GetText();
auto wssPort = std::stoi(this->wssPortInput->GetText());
auto httpPort = std::stoi(this->httpPortInput->GetText());
auto wssPort = getIntFromTextInput(*this->wssPortInput, 7905);
auto httpPort = getIntFromTextInput(*this->httpPortInput, 7906);
auto password = this->pwInput->GetText();
auto const wssTls = this->wssTlsCheckbox->IsChecked();
auto const httpTls = this->httpTlsCheckbox->IsChecked();

View File

@ -565,7 +565,7 @@ int HttpServer::HandleAudioTrackRequest(
#endif
if (response) {
/* 'format' will be valid if we're transocding. otherwise, extract the extension
/* 'format' will be valid if we're transcoding. otherwise, extract the extension
from the filename. the client can use this as a hint when naming downloaded files */
std::string extension = format.size() ? format : fileExtension(filename);
MHD_add_response_header(response, "X-musikcube-File-Extension", extension.c_str());