summaryrefslogtreecommitdiffstats
path: root/daemon.c
diff options
context:
space:
mode:
authorUsman Akinyemi <usmanakinyemi202@gmail.com>2024-10-24 02:24:56 +0200
committerTaylor Blau <me@ttaylorr.com>2024-10-24 20:03:43 +0200
commitcc4023477f3c958b77c64b7f36f91b4f9d7c5a58 (patch)
treebd61c6cec5ebe9ca7d6133b5771e69877e03dfd9 /daemon.c
parentThe third batch (diff)
downloadgit-cc4023477f3c958b77c64b7f36f91b4f9d7c5a58.tar.xz
git-cc4023477f3c958b77c64b7f36f91b4f9d7c5a58.zip
daemon: replace atoi() with strtoul_ui() and strtol_i()
Replace atoi() with strtoul_ui() for --timeout and --init-timeout (non-negative integers) and with strtol_i() for --max-connections (signed integers). This improves error handling and input validation by detecting invalid values and providing clear error messages. Update tests to ensure these arguments are properly validated. Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>
Diffstat (limited to 'daemon.c')
-rw-r--r--daemon.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/daemon.c b/daemon.c
index cb946e3c95..a40e435c63 100644
--- a/daemon.c
+++ b/daemon.c
@@ -4,6 +4,7 @@
#include "abspath.h"
#include "config.h"
#include "environment.h"
+#include "gettext.h"
#include "path.h"
#include "pkt-line.h"
#include "protocol.h"
@@ -1308,17 +1309,20 @@ int cmd_main(int argc, const char **argv)
continue;
}
if (skip_prefix(arg, "--timeout=", &v)) {
- timeout = atoi(v);
+ if (strtoul_ui(v, 10, &timeout))
+ die(_("invalid timeout '%s', expecting a non-negative integer"), v);
continue;
}
if (skip_prefix(arg, "--init-timeout=", &v)) {
- init_timeout = atoi(v);
+ if (strtoul_ui(v, 10, &init_timeout))
+ die(_("invalid init-timeout '%s', expecting a non-negative integer"), v);
continue;
}
if (skip_prefix(arg, "--max-connections=", &v)) {
- max_connections = atoi(v);
+ if (strtol_i(v, 10, &max_connections))
+ die(_("invalid max-connections '%s', expecting an integer"), v);
if (max_connections < 0)
- max_connections = 0; /* unlimited */
+ max_connections = 0; /* unlimited */
continue;
}
if (!strcmp(arg, "--strict-paths")) {