diff options
author | Simon Warta <[email protected]> | 2015-08-11 10:02:32 +0200 |
---|---|---|
committer | Simon Warta <[email protected]> | 2015-08-11 10:02:51 +0200 |
commit | 7264369898fda03bfb3926d755bdb3370b6bf25d (patch) | |
tree | a54d164f4738a8808bdc43595dc01f4e8e7f806b /src/lib | |
parent | 765f445f3cef73f5bd6647eab1b99c39a7ad24cb (diff) |
Strict uint32 parsing
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/utils/parsing.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lib/utils/parsing.cpp b/src/lib/utils/parsing.cpp index 605823082..4feea8d60 100644 --- a/src/lib/utils/parsing.cpp +++ b/src/lib/utils/parsing.cpp @@ -20,6 +20,16 @@ u32bit to_u32bit(const std::string& str) { try { + // std::stoul is not strict enough. Ensure that str is digit only [0-9]* + for (const char chr : str) + { + if (chr < '0' || chr > '9') + { + auto chrAsString = std::string(1, chr); + throw Invalid_Argument("String contains non-digit char: " + chrAsString); + } + } + const auto integerValue = std::stoul(str); // integerValue might be uint64 |