]> git.ipfire.org Git - people/ms/network.git/commitdiff
config: Fail if there is garbage after intergers
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Apr 2023 10:46:32 +0000 (10:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 15 Apr 2023 10:46:32 +0000 (10:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/networkd/config.c

index d879ace761d86f54470cd4caefc4f1afe26b70cb..42e01727fc8955a24f53e7debb30815caf28f96b 100644 (file)
@@ -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) {