Skip to content

Commit

Permalink
Fix stack overflow
Browse files Browse the repository at this point in the history
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
  • Loading branch information
igorcanadi committed Nov 19, 2013
1 parent 07e8078 commit ec0acfb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions utilities/ttl/db_ttl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ 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.
// Returns false if could not get the current_time, true if append succeeds
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;
Expand All @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions utilities/ttl/db_ttl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit ec0acfb

Please sign in to comment.