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
main
Igor Canadi 11 years ago
parent 07e8078b17
commit ec0acfbca1
  1. 10
      utilities/ttl/db_ttl.cc
  2. 10
      utilities/ttl/db_ttl.h

@ -61,8 +61,8 @@ Status UtilityDB::OpenTtlDB(
} }
// Gives back the current time // Gives back the current time
Status DBWithTTL::GetCurrentTime(int32_t& curtime) { Status DBWithTTL::GetCurrentTime(int64_t& curtime) {
return Env::Default()->GetCurrentTime((int64_t*)&curtime); return Env::Default()->GetCurrentTime(&curtime);
} }
// Appends the current timestamp to the string. // 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) { Status DBWithTTL::AppendTS(const Slice& val, std::string& val_with_ts) {
val_with_ts.reserve(kTSLength + val.size()); val_with_ts.reserve(kTSLength + val.size());
char ts_string[kTSLength]; char ts_string[kTSLength];
int32_t curtime; int64_t curtime;
Status st = GetCurrentTime(curtime); Status st = GetCurrentTime(curtime);
if (!st.ok()) { if (!st.ok()) {
return st; return st;
} }
EncodeFixed32(ts_string, curtime); EncodeFixed32(ts_string, (int32_t)curtime);
val_with_ts.append(val.data(), val.size()); val_with_ts.append(val.data(), val.size());
val_with_ts.append(ts_string, kTSLength); val_with_ts.append(ts_string, kTSLength);
return st; 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 if (ttl <= 0) { // Data is fresh if TTL is non-positive
return false; return false;
} }
int32_t curtime; int64_t curtime;
if (!GetCurrentTime(curtime).ok()) { if (!GetCurrentTime(curtime).ok()) {
return false; // Treat the data as fresh if could not get current time return false; // Treat the data as fresh if could not get current time
} }

@ -100,7 +100,7 @@ class DBWithTTL : public StackableDB {
static Status StripTS(std::string* str); 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 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 // Augment the *new_value with the ttl time-stamp
int32_t curtime; int64_t curtime;
if (!DBWithTTL::GetCurrentTime(curtime).ok()) { if (!DBWithTTL::GetCurrentTime(curtime).ok()) {
Log(logger, "Error: Could not get current time to be attached internally " Log(logger, "Error: Could not get current time to be attached internally "
"to the new value."); "to the new value.");
return false; return false;
} else { } else {
char ts_string[ts_len]; char ts_string[ts_len];
EncodeFixed32(ts_string, curtime); EncodeFixed32(ts_string, (int32_t)curtime);
new_value->append(ts_string, ts_len); new_value->append(ts_string, ts_len);
return true; return true;
} }
@ -337,14 +337,14 @@ class TtlMergeOperator : public MergeOperator {
} }
// Augment the *new_value with the ttl time-stamp // Augment the *new_value with the ttl time-stamp
int32_t curtime; int64_t curtime;
if (!DBWithTTL::GetCurrentTime(curtime).ok()) { if (!DBWithTTL::GetCurrentTime(curtime).ok()) {
Log(logger, "Error: Could not get current time to be attached internally " Log(logger, "Error: Could not get current time to be attached internally "
"to the new value."); "to the new value.");
return false; return false;
} else { } else {
char ts_string[ts_len]; char ts_string[ts_len];
EncodeFixed32(ts_string, curtime); EncodeFixed32(ts_string, (int32_t)curtime);
new_value->append(ts_string, ts_len); new_value->append(ts_string, ts_len);
return true; return true;
} }

Loading…
Cancel
Save