From cb19e7411f17713adcfefbd45988dc6b18174914 Mon Sep 17 00:00:00 2001 From: sdong Date: Tue, 9 Jul 2019 11:01:12 -0700 Subject: [PATCH] Fix bugs in DBWALTest.kTolerateCorruptedTailRecords triggered by #5520 (#5550) Summary: https://github.com/facebook/rocksdb/pull/5520 caused a buffer overflow bug in DBWALTest.kTolerateCorruptedTailRecords. Fix it. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5550 Test Plan: Run the test in UBSAN. It used to fail. Not it succeeds. Differential Revision: D16165516 fbshipit-source-id: 42c56a6bc64eb091f054b87757fcbef60da825f7 --- db/db_wal_test.cc | 4 +++- file/file_util.cc | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/db/db_wal_test.cc b/db/db_wal_test.cc index 4859bdc90..2d5e7bc1d 100644 --- a/db/db_wal_test.cc +++ b/db/db_wal_test.cc @@ -824,7 +824,9 @@ class RecoveryTestHelper { // Create WAL files with values filled in static void FillData(DBWALTest* test, const Options& options, const size_t wal_count, size_t* count) { - const ImmutableDBOptions db_options(options); + // Calling internal functions requires sanitized options. + Options sanitized_options = SanitizeOptions(test->dbname_, options); + const ImmutableDBOptions db_options(sanitized_options); *count = 0; diff --git a/file/file_util.cc b/file/file_util.cc index 050d25da1..ee52bf640 100644 --- a/file/file_util.cc +++ b/file/file_util.cc @@ -110,6 +110,7 @@ Status DeleteDBFile(const ImmutableDBOptions* db_options, bool IsWalDirSameAsDBPath(const ImmutableDBOptions* db_options) { bool same = false; + assert(!db_options->db_paths.empty()); Status s = db_options->env->AreFilesSame(db_options->wal_dir, db_options->db_paths[0].path, &same); if (s.IsNotSupported()) {