From 9c1735e33f9335e6cd5bbc45f0e256b437b8e7f3 Mon Sep 17 00:00:00 2001 From: Michael Theall Date: Sun, 13 Jun 2021 11:36:20 -0500 Subject: [PATCH] Fix privileged port logic --- source/ftpConfig.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/source/ftpConfig.cpp b/source/ftpConfig.cpp index ba938d3..3c9177b 100644 --- a/source/ftpConfig.cpp +++ b/source/ftpConfig.cpp @@ -3,7 +3,7 @@ // - RFC 3659 (https://tools.ietf.org/html/rfc3659) // - suggested implementation details from https://cr.yp.to/ftp/filesystem.html // -// Copyright (C) 2020 Michael Theall +// Copyright (C) 2021 Michael Theall // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -283,15 +283,22 @@ bool FtpConfig::setPort (std::string const &port_) bool FtpConfig::setPort (std::uint16_t const port_) { - if (port_ < 1024 -#if !defined(NDS) && !defined(_3DS) - && port_ != 0 -#endif - ) +#ifdef __SWITCH__ + // Switch is not allowed < 1024, except 0 + if (port_ < 1024 && port_ != 0) { errno = EPERM; return false; } +#elif defined(NDS) || defined(_3DS) + // 3DS is allowed < 1024, but not 0 + // NDS is allowed < 1024, but 0 crashes the app + if (port_ == 0) + { + errno = EPERM; + return false; + } +#endif m_port = port_; return true;