Skip to content

Commit 2d4b51c

Browse files
daverigbytrondn
authored andcommitted
MB-29523: Avoid undefined behaviour upon zero-length SerialisedDocKey
As identified by UBSan, if we try to create a zero-length SerialisedDocKey (which is valid); the current implementation passes a null pointer to memcpy: [ RUN ] MutationLogTest.Logging runtime error: null pointer passed as argument 2, which is declared to never be null #0 0x11e9309 in SerialisedDocKey::SerialisedDocKey(DocKey) kv_engine/engines/ep/src/storeddockey.h:277 #1 0x11e9309 in MutationLogEntryV2::MutationLogEntryV2(MutationLogType, unsigned short, DocKey const&) kv_engine/engines/ep/src/mutation_log_entry.h:310 #2 0x11e9309 in MutationLogEntryV2::MutationLogEntryV2(MutationLogType, unsigned short) kv_engine/engines/ep/src/mutation_log_entry.h:321 #3 0x11e9309 in MutationLogEntryV2::newEntry(unsigned char*, MutationLogType, unsigned short) kv_engine/engines/ep/src/mutation_log_entry.h:223 #4 0x11e9309 in MutationLog::commit1() kv_engine/engines/ep/src/mutation_log.cc:322 Fix by using std::copy instead. Change-Id: I0994f1522efeb046c58da375053b6257fdc89a6a Reviewed-on: http://review.couchbase.org/93762 Tested-by: Build Bot <[email protected]> Reviewed-by: Trond Norbye <[email protected]>
1 parent f18b981 commit 2d4b51c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

engines/ep/src/storeddockey.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class SerialisedDocKey : public DocKeyInterface<SerialisedDocKey> {
274274
length = gsl::narrow_cast<uint8_t>(key.size());
275275
// Copy the data into bytes, which should be allocated into a larger
276276
// buffer.
277-
std::memcpy(bytes, key.data(), key.size());
277+
std::copy(key.data(), key.data() + key.size(), bytes);
278278
}
279279

280280
/**

0 commit comments

Comments
 (0)