descriptors: Reject + sign in ParseKeyPathNum

This commit is contained in:
MarcoFalke
2025-04-28 16:33:05 +02:00
parent d62c2d82e1
commit fa6f77ed3c
2 changed files with 7 additions and 6 deletions

View File

@@ -1423,16 +1423,16 @@ std::optional<uint32_t> ParseKeyPathNum(std::span<const char> elem, bool& apostr
apostrophe = last == '\'';
}
}
uint32_t p;
if (!ParseUInt32(std::string(elem.begin(), elem.end()), &p)) {
error = strprintf("Key path value '%s' is not a valid uint32", std::string(elem.begin(), elem.end()));
const auto p{ToIntegral<uint32_t>(std::string_view{elem.begin(), elem.end()})};
if (!p) {
error = strprintf("Key path value '%s' is not a valid uint32", std::string_view{elem.begin(), elem.end()});
return std::nullopt;
} else if (p > 0x7FFFFFFFUL) {
error = strprintf("Key path value %u is out of range", p);
} else if (*p > 0x7FFFFFFFUL) {
error = strprintf("Key path value %u is out of range", *p);
return std::nullopt;
}
return std::make_optional<uint32_t>(p | (((uint32_t)hardened) << 31));
return std::make_optional<uint32_t>(*p | (((uint32_t)hardened) << 31));
}
/**