From b15379dceab5a7ef387561af35b73c1b6def93b0 Mon Sep 17 00:00:00 2001 From: Zhongyi Xie Date: Thu, 9 Aug 2018 10:58:34 -0700 Subject: [PATCH] fix use-after-free error involving a temporary string (#4240) Summary: In the current code, `error_msg` is pointing to the inner buffer of a temporary std::string object. When `error_msg` is used to construct the error message, that array is already released. This PR will fix this bug by copying the string to a local variable. Fixes https://github.com/facebook/rocksdb/issues/4239 Pull Request resolved: https://github.com/facebook/rocksdb/pull/4240 Differential Revision: D9204334 Pulled By: miasantreble fbshipit-source-id: 0ac599e166ae0a4ec413e32d8b8853d7c5fba878 --- db/db_impl_open.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/db_impl_open.cc b/db/db_impl_open.cc index 6b639191c..4e68327dd 100644 --- a/db/db_impl_open.cc +++ b/db/db_impl_open.cc @@ -361,7 +361,7 @@ Status DBImpl::Recover( s = env_->NewRandomAccessFile(IdentityFileName(dbname_), &idfile, customized_env); if (!s.ok()) { - const char* error_msg = s.ToString().c_str(); + std::string error_str = s.ToString(); // Check if unsupported Direct I/O is the root cause customized_env.use_direct_reads = false; s = env_->NewRandomAccessFile(IdentityFileName(dbname_), &idfile, @@ -371,7 +371,7 @@ Status DBImpl::Recover( "Direct I/O is not supported by the specified DB."); } else { return Status::InvalidArgument( - "Found options incompatible with filesystem", error_msg); + "Found options incompatible with filesystem", error_str.c_str()); } } }