From: Michael Tremer Date: Sat, 15 Apr 2023 10:46:32 +0000 (+0000) Subject: config: Fail if there is garbage after intergers X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=92c8a4fe8806d0a84f4c546be75c0f08dc6d7200;p=network.git config: Fail if there is garbage after intergers Signed-off-by: Michael Tremer --- 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) {