diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-11-22 14:11:00 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-11-22 14:11:00 +0100 |
commit | 204cff5c192eeb60205c6c33914ed506c529780a (patch) | |
tree | 656dbd38d5521774169cacab29b68959067fa305 /common | |
parent | c39645bed5c30d60d726571a2741b31df62b9ca2 (diff) |
Avoid UB in Session::setHash()
Ubsan says that signed integer overflow is happening here:
#0 0xec344a in Session::setHash(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) common/Session.cpp:267:17
#1 0x918b54 in DocumentBroker::load(std::shared_ptr<ClientSession> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) wsd/DocumentBroker.cpp:682:18
...
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior common/Session.cpp:267:17 in
(While running unit_wopi_watermark.)
Change-Id: Idcb1692f6d5d0df8be35dc557d2d72a345acbcf4
Diffstat (limited to 'common')
-rw-r--r-- | common/Session.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/common/Session.cpp b/common/Session.cpp index 9495cc99a..1e4c76573 100644 --- a/common/Session.cpp +++ b/common/Session.cpp @@ -257,8 +257,8 @@ void Session::getIOStats(uint64_t &sent, uint64_t &recv) void Session::setHash(const std::string& text) { - int hash = 0x811C9DC5; - int prime = 0x1000193; + unsigned int hash = 0x811C9DC5; + unsigned int prime = 0x1000193; if (!text.empty()) { @@ -268,7 +268,7 @@ void Session::setHash(const std::string& text) hash *= prime; } } - _hash = abs(hash); + _hash = abs(static_cast<int>(hash)); } |