Fix up backupable_db stack corruption.

Summary:
Fix up OACR(Lint) warnings.
Closes https://github.com/facebook/rocksdb/pull/3674

Differential Revision: D7563869

Pulled By: ajkr

fbshipit-source-id: 8c1e5045c8a6a2d85b2933fdbc60fde93bf0c9de
main
Dmitri Smirnov 7 years ago committed by Facebook Github Bot
parent d2bcd7611f
commit 5ec382b918
  1. 4
      third-party/gtest-1.7.0/fused-src/gtest/gtest.h
  2. 12
      util/status.cc
  3. 6
      utilities/backupable/backupable_db.cc

@ -3410,10 +3410,6 @@ inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996 /* deprecated function */)
inline const char* StrNCpy(char* dest, const char* src, size_t n) {
return strncpy(dest, src, n);
}
// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and // ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
// StrError() aren't needed on Windows CE at this time and thus not // StrError() aren't needed on Windows CE at this time and thus not
// defined there. // defined there.

@ -15,9 +15,17 @@
namespace rocksdb { namespace rocksdb {
const char* Status::CopyState(const char* state) { const char* Status::CopyState(const char* state) {
const size_t cch =
std::strlen(state) + 1; // +1 for the null terminator
char* const result = char* const result =
new char[std::strlen(state) + 1]; // +1 for the null terminator new char[cch];
std::strcpy(result, state); #ifdef OS_WIN
errno_t ret;
ret = strncpy_s(result, cch, state, cch - 1);
assert(ret == 0);
#else
std::strncpy(result, state, cch - 1);
#endif
return result; return result;
} }

@ -1770,7 +1770,8 @@ Status BackupEngineImpl::BackupMeta::StoreToFile(bool sync) {
} }
char writelen_temp[19]; char writelen_temp[19];
if (len + sprintf(writelen_temp, "%" ROCKSDB_PRIszt "\n", files_.size()) >= buf_size) { if (len + snprintf(writelen_temp, sizeof(writelen_temp),
"%" ROCKSDB_PRIszt "\n", files_.size()) >= buf_size) {
backup_meta_file->Append(Slice(buf.get(), len)); backup_meta_file->Append(Slice(buf.get(), len));
buf.reset(); buf.reset();
unique_ptr<char[]> new_reset_buf(new char[max_backup_meta_file_size_]); unique_ptr<char[]> new_reset_buf(new char[max_backup_meta_file_size_]);
@ -1785,7 +1786,8 @@ Status BackupEngineImpl::BackupMeta::StoreToFile(bool sync) {
for (const auto& file : files_) { for (const auto& file : files_) {
// use crc32 for now, switch to something else if needed // use crc32 for now, switch to something else if needed
size_t newlen = len + file->filename.length() + sprintf(writelen_temp, " crc32 %u\n", file->checksum_value); size_t newlen = len + file->filename.length() + snprintf(writelen_temp,
sizeof(writelen_temp), " crc32 %u\n", file->checksum_value);
const char *const_write = writelen_temp; const char *const_write = writelen_temp;
if (newlen >= buf_size) { if (newlen >= buf_size) {
backup_meta_file->Append(Slice(buf.get(), len)); backup_meta_file->Append(Slice(buf.get(), len));

Loading…
Cancel
Save