From 92c8a4fe8806d0a84f4c546be75c0f08dc6d7200 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 15 Apr 2023 10:46:32 +0000 Subject: [PATCH] config: Fail if there is garbage after intergers Signed-off-by: Michael Tremer --- src/networkd/config.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/networkd/config.c b/src/networkd/config.c index d879ace7..42e01727 100644 --- a/src/networkd/config.c +++ b/src/networkd/config.c @@ -348,13 +348,23 @@ int nw_config_set(nw_config* config, const char* key, const char* value) { } int nw_config_get_int(nw_config* config, const char* key, const int __default) { + char* p = NULL; + int r; + const char* value = nw_config_get(config, key); // Return zero if not set if (!value) return __default; - return strtoul(value, NULL, 10); + // Parse the input + r = strtoul(value, &p, 10); + + // If we have characters following the input, we throw it away + if (p) + return __default; + + return r; } int nw_config_set_int(nw_config* config, const char* key, const int value) { -- 2.47.3