From 402dd2078cc8ecb83564c7ee494dad0feb11b9df Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 18 Nov 2019 12:35:11 +0000 Subject: db_lmdb: guard against non NUL terminated keys --- src/blockchain_db/lmdb/db_lmdb.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/blockchain_db/lmdb/db_lmdb.cpp') diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index f978ef307..f46e53f3d 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -163,7 +163,15 @@ int BlockchainLMDB::compare_string(const MDB_val *a, const MDB_val *b) { const char *va = (const char*) a->mv_data; const char *vb = (const char*) b->mv_data; - return strcmp(va, vb); + const size_t sz = std::min(a->mv_size, b->mv_size); + int ret = strncmp(va, vb, sz); + if (ret) + return ret; + if (a->mv_size < b->mv_size) + return -1; + if (a->mv_size > b->mv_size) + return 1; + return 0; } } -- cgit v1.2.3