]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Validate unsigned integer JSON config values 1163/head
authorDevansh-567 <devansh.jay.singh@gmail.com>
Fri, 26 Jun 2026 07:27:53 +0000 (12:57 +0530)
committerDevansh-567 <devansh.jay.singh@gmail.com>
Fri, 26 Jun 2026 08:53:37 +0000 (14:23 +0530)
client/snbk/JsonFile.cc

index 0a40d6dfae962202e7bee2d1a4ff2f67300ad133..4cfd3c0b255209c62d5dbc09b5274ec57b6892a2 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/stat.h>
 #include <functional>
 #include <memory>
+#include <limits>
 
 #include "snapper/Exception.h"
 #include "snapper/AppUtil.h"
@@ -181,7 +182,13 @@ namespace snapper
        if (!json_object_is_type(child, json_type_int) && !json_object_is_type(child, json_type_string))
            return false;
 
-       value = json_object_get_int(child);
+       int64_t val64 = json_object_get_int64(child);
+       if (val64 < 0 || val64 > std::numeric_limits<unsigned int>::max())
+       {
+           SN_THROW(Exception(sformat("Value out of bounds for unsigned int key '%s'", name)));
+       }
+
+       value = (unsigned int)val64;
 
        return true;
     }