color_t: validate hex string input (resolves #9030)

This commit is contained in:
Charles Dang 2024-06-24 17:24:21 -04:00
parent e67a91caf2
commit 6f32635788

View file

@ -65,6 +65,10 @@ color_t color_t::from_hex_string(const std::string& c)
throw std::invalid_argument("Color hex string should be exactly 6 digits");
}
if(!std::all_of(c.begin(), c.end(), [](const char& ch) { return std::isxdigit(ch) != 0; })) {
throw std::invalid_argument("Color hex string contains invalid characters");
}
unsigned long temp_c = std::strtol(c.c_str(), nullptr, 16);
return {