commit d0cbf8921ecdf1166ba90dd21fca7e1a0f8c644e
parent e7f56d1a45c77bff073eb6fe1f68ddcd495193c7
Author: Francesco Saccone <francesco@francescosaccone.com>
Date: Mon, 31 Mar 2025 15:05:34 +0200
refactor: do port validation while the arguments are being parsed
Signed-off-by: Francesco Saccone <francesco@francescosaccone.com>
Diffstat:
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/hermes.c b/hermes.c
@@ -44,6 +44,10 @@ main(int argc, char *argv[]) {
switch (argument[1]) {
case 'p':
port = atoi(argv[i + 1]);
+ if (port < 1 || port > 65535) {
+ print_error("error: port must be between 1 and 65535.");
+ return 1;
+ };
i++;
break;
case 'i':
@@ -82,11 +86,6 @@ main(int argc, char *argv[]) {
}
}
- if (port < 1 || port > 65535) {
- print_error("error: port must be between 1 and 65535.");
- return 1;
- };
-
user = getpwnam(user_name);
group = getgrnam(group_name);