From 4148d3fdac4437e4f4246c66d908e18979c9e4cf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 21 Jul 2021 15:02:15 +0900 Subject: [PATCH] Add a bit more safety to argument parsing logic --- osu.Desktop/Program.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index 0bcbc696bc..0b81e2d127 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -17,18 +17,25 @@ namespace osu.Desktop { public static class Program { + private const string base_game_name = @"osu"; + [STAThread] public static int Main(string[] args) { // Back up the cwd before DesktopGameHost changes it var cwd = Environment.CurrentDirectory; - string gameName = @"osu"; + string gameName = base_game_name; bool tournamentClient = false; - foreach (var arg in args.Select(s => s.Split('='))) + foreach (var arg in args) { - switch (arg[0]) + var split = arg.Split('='); + + var key = split[0]; + var val = split[1]; + + switch (key) { case "--tournament": tournamentClient = true; @@ -36,9 +43,12 @@ public static int Main(string[] args) case "--debug-client-id": if (!DebugUtils.IsDebugBuild) - break; + throw new InvalidOperationException("Cannot use this argument in a non-debug build."); - gameName = $"{gameName}-{int.Parse(arg[1])}"; + if (!int.TryParse(val, out int clientID)) + throw new ArgumentException("Provided client ID must be an integer."); + + gameName = $"{base_game_name}-{clientID}"; break; } }