db_lmdb: guard against non NUL terminated keys

This commit is contained in:
moneromooo-monero 2019-11-18 12:35:11 +00:00
parent fe3f6a3e6b
commit 402dd2078c
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
1 changed files with 9 additions and 1 deletions

View File

@ -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;
}
}