aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-01-07 19:11:27 -0600
committerGitHub <noreply@github.com>2023-01-07 19:11:27 -0600
commitd74137862bdbfab63a6c1ad61b8a22f650d99332 (patch)
treecc1d9b93f714767adf096e52a9087be69ef694f8 /src
parentff5f0ac6c93f2b49ba259e7093fb92fa873116c6 (diff)
parent7794a480f8320ad20b9dd786409a047b9a3db33a (diff)
downloadslskd-d74137862bdbfab63a6c1ad61b8a22f650d99332.tar.gz
Merge pull request #828 from slskd/secrets
Refactor the --generate-secret command to produce a friendlier error if the user doesn't supply a value
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Program.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 28ef7279..969ff53f 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -243,7 +243,17 @@ namespace slskd
// populate the properties above so that we can override the default config file if needed, and to
// check if the application is being run in command mode (run task and quit).
EnvironmentVariables.Populate(prefix: EnvironmentVariablePrefix);
+
+ try
+ {
Arguments.Populate(clearExistingValues: false);
+ }
+ catch (Exception ex)
+ {
+ // this is pretty hacky, but i don't have a good way of trapping errors that bubble up here.
+ Log.Error($"Invalid command line input: {ex.Message.Replace(". See inner exception for details.", string.Empty)}");
+ return;
+ }
// if a user has used one of the arguments above, perform the requested task, then quit
if (ShowVersion)
@@ -283,6 +293,12 @@ namespace slskd
if (GenerateSecret > 0)
{
+ if (GenerateSecret < 16 || GenerateSecret > 255)
+ {
+ Log.Error("Invalid command line input: secret length must be between 16 and 255, inclusive");
+ return;
+ }
+
Log.Information(Cryptography.Random.GetBytes(GenerateSecret).ToBase62());
return;
}