From ec0acfbca115fc6cda85d2246474ee5148d80af8 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Mon, 18 Nov 2013 20:56:21 -0800 Subject: [PATCH] Fix stack overflow Summary: Sure, let me put 8 bytes in that int32_t. Brought to you by ASAN! Test Plan: ttl_test Reviewers: dhruba, haobo, kailiu, emayanke Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D14193 --- utilities/ttl/db_ttl.cc | 10 +++++----- utilities/ttl/db_ttl.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/utilities/ttl/db_ttl.cc b/utilities/ttl/db_ttl.cc index d8843d172..a019102d9 100644 --- a/utilities/ttl/db_ttl.cc +++ b/utilities/ttl/db_ttl.cc @@ -61,8 +61,8 @@ Status UtilityDB::OpenTtlDB( } // Gives back the current time -Status DBWithTTL::GetCurrentTime(int32_t& curtime) { - return Env::Default()->GetCurrentTime((int64_t*)&curtime); +Status DBWithTTL::GetCurrentTime(int64_t& curtime) { + return Env::Default()->GetCurrentTime(&curtime); } // Appends the current timestamp to the string. @@ -70,12 +70,12 @@ Status DBWithTTL::GetCurrentTime(int32_t& curtime) { Status DBWithTTL::AppendTS(const Slice& val, std::string& val_with_ts) { val_with_ts.reserve(kTSLength + val.size()); char ts_string[kTSLength]; - int32_t curtime; + int64_t curtime; Status st = GetCurrentTime(curtime); if (!st.ok()) { return st; } - EncodeFixed32(ts_string, curtime); + EncodeFixed32(ts_string, (int32_t)curtime); val_with_ts.append(val.data(), val.size()); val_with_ts.append(ts_string, kTSLength); return st; @@ -102,7 +102,7 @@ bool DBWithTTL::IsStale(const Slice& value, int32_t ttl) { if (ttl <= 0) { // Data is fresh if TTL is non-positive return false; } - int32_t curtime; + int64_t curtime; if (!GetCurrentTime(curtime).ok()) { return false; // Treat the data as fresh if could not get current time } diff --git a/utilities/ttl/db_ttl.h b/utilities/ttl/db_ttl.h index ee6382b65..ffee0ccf2 100644 --- a/utilities/ttl/db_ttl.h +++ b/utilities/ttl/db_ttl.h @@ -100,7 +100,7 @@ class DBWithTTL : public StackableDB { static Status StripTS(std::string* str); - static Status GetCurrentTime(int32_t& curtime); + static Status GetCurrentTime(int64_t& curtime); static const uint32_t kTSLength = sizeof(int32_t); // size of timestamp @@ -302,14 +302,14 @@ class TtlMergeOperator : public MergeOperator { } // Augment the *new_value with the ttl time-stamp - int32_t curtime; + int64_t curtime; if (!DBWithTTL::GetCurrentTime(curtime).ok()) { Log(logger, "Error: Could not get current time to be attached internally " "to the new value."); return false; } else { char ts_string[ts_len]; - EncodeFixed32(ts_string, curtime); + EncodeFixed32(ts_string, (int32_t)curtime); new_value->append(ts_string, ts_len); return true; } @@ -337,14 +337,14 @@ class TtlMergeOperator : public MergeOperator { } // Augment the *new_value with the ttl time-stamp - int32_t curtime; + int64_t curtime; if (!DBWithTTL::GetCurrentTime(curtime).ok()) { Log(logger, "Error: Could not get current time to be attached internally " "to the new value."); return false; } else { char ts_string[ts_len]; - EncodeFixed32(ts_string, curtime); + EncodeFixed32(ts_string, (int32_t)curtime); new_value->append(ts_string, ts_len); return true; }