Skip to content

Commit 03da4b0

Browse files
Fix a crash inside InitializeLru (#898)
During testing was found that function InitializeLru could crash during expiration parsing, the data length was not taken into account when it was parsed, and std::stol throw an exception. Resolves: OLPEDGE-2029 Signed-off-by: Mykhailo Kuchma <ext-mykhailo.kuchma@here.com>
1 parent 33a37dc commit 03da4b0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,11 @@ void DefaultCacheImpl::InitializeLru() {
341341
}
342342

343343
if (expiration_key) {
344-
props.expiry = std::stol(value.data());
344+
// value.data() could point to a value without null character at the
345+
// end, this could cause exception in std::stol. This is fixed by
346+
// constructing a string, (We rely on small string optimization here).
347+
std::string timestamp(value.data(), value.size());
348+
props.expiry = std::stol(timestamp.c_str());
345349
} else {
346350
props.size = value.size();
347351
}

0 commit comments

Comments
 (0)