Skip to content

Commit 0cfd95d

Browse files
committed
MB-28633: Don't create a temp std::string in ScanContext::manageSeparator
When creating a DocKey (which is just a view on the underlying data) in ScanContext::manageSeparator(), don't create a temporary std::string. This is illegal as when the string goes out of scope (after calling DocKey::make() at line 34) the resulting 'cKey2' will be pointing at now-freed heap (assuming no small-string optimization), or invalid stack (with small-string optimization). Change-Id: I055d0d52277974b25b328f5fc3ca96b6fba9b6fa Reviewed-on: http://review.couchbase.org/90796 Reviewed-by: Trond Norbye <[email protected]> Reviewed-by: Tim Bradgate <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent a2622a0 commit 0cfd95d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

engines/ep/src/collections/scan_context.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ bool ScanContext::manageSeparator(const ::DocKey& key) {
3232
// Make a new Collections::DocKey from cKey.getKey, which returns
3333
// <uid>:<new_sep>, thus getKey will return <new_sep>
3434
auto cKey2 = Collections::DocKey::make(
35-
{{cKey.getKey().data(), cKey.getKey().size()},
35+
{reinterpret_cast<const uint8_t*>(cKey.getKey().data()),
36+
cKey.getKey().size(),
3637
DocNamespace::System});
3738
separator.assign(cKey2.getKey().data(), cKey2.getKey().size());
3839
return true; // return true because we've changed

0 commit comments

Comments
 (0)