Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ip adress sanitization for MP Menu screen #196

Merged
merged 3 commits into from
Apr 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions NebulaPatcher/Patches/Dynamic/UIMainMenu_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@ private static void OnJoinGameButtonClick()
string ip = parts[0];
int port;

//remove copy and paste mistakes and update the textbox to prevent user confusion in case of invalid ip address
ip = ip.Trim('\r', '\n', '\t', ' ');
Copy link
Contributor

Choose a reason for hiding this comment

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

These are all already considered whitespace by c#

hostIPAdressInput.text = parts.Length == 1 ? ip : ip + ":" + parts[1];

if (!System.Net.IPAddress.TryParse(ip, out _))
{
//log, notify user and early return to prevent crash on invalid strings
InGamePopup.ShowWarning("Invalid connection string", "Note: This mod currently only accepts IPv4 Addresses.", "OK");
Mushroom marked this conversation as resolved.
Show resolved Hide resolved
Log.Info($"IP String {ip} is not a valid IPv4 String");
return;
}

if (parts.Length == 1)
{
port = Config.DefaultPort;
Expand Down