Skip to content

Commit ec0acfb

Browse files
committed
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
1 parent 07e8078 commit ec0acfb

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

utilities/ttl/db_ttl.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ Status UtilityDB::OpenTtlDB(
6161
}
6262

6363
// Gives back the current time
64-
Status DBWithTTL::GetCurrentTime(int32_t& curtime) {
65-
return Env::Default()->GetCurrentTime((int64_t*)&curtime);
64+
Status DBWithTTL::GetCurrentTime(int64_t& curtime) {
65+
return Env::Default()->GetCurrentTime(&curtime);
6666
}
6767

6868
// Appends the current timestamp to the string.
6969
// Returns false if could not get the current_time, true if append succeeds
7070
Status DBWithTTL::AppendTS(const Slice& val, std::string& val_with_ts) {
7171
val_with_ts.reserve(kTSLength + val.size());
7272
char ts_string[kTSLength];
73-
int32_t curtime;
73+
int64_t curtime;
7474
Status st = GetCurrentTime(curtime);
7575
if (!st.ok()) {
7676
return st;
7777
}
78-
EncodeFixed32(ts_string, curtime);
78+
EncodeFixed32(ts_string, (int32_t)curtime);
7979
val_with_ts.append(val.data(), val.size());
8080
val_with_ts.append(ts_string, kTSLength);
8181
return st;
@@ -102,7 +102,7 @@ bool DBWithTTL::IsStale(const Slice& value, int32_t ttl) {
102102
if (ttl <= 0) { // Data is fresh if TTL is non-positive
103103
return false;
104104
}
105-
int32_t curtime;
105+
int64_t curtime;
106106
if (!GetCurrentTime(curtime).ok()) {
107107
return false; // Treat the data as fresh if could not get current time
108108
}

utilities/ttl/db_ttl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class DBWithTTL : public StackableDB {
100100

101101
static Status StripTS(std::string* str);
102102

103-
static Status GetCurrentTime(int32_t& curtime);
103+
static Status GetCurrentTime(int64_t& curtime);
104104

105105
static const uint32_t kTSLength = sizeof(int32_t); // size of timestamp
106106

@@ -302,14 +302,14 @@ class TtlMergeOperator : public MergeOperator {
302302
}
303303

304304
// Augment the *new_value with the ttl time-stamp
305-
int32_t curtime;
305+
int64_t curtime;
306306
if (!DBWithTTL::GetCurrentTime(curtime).ok()) {
307307
Log(logger, "Error: Could not get current time to be attached internally "
308308
"to the new value.");
309309
return false;
310310
} else {
311311
char ts_string[ts_len];
312-
EncodeFixed32(ts_string, curtime);
312+
EncodeFixed32(ts_string, (int32_t)curtime);
313313
new_value->append(ts_string, ts_len);
314314
return true;
315315
}
@@ -337,14 +337,14 @@ class TtlMergeOperator : public MergeOperator {
337337
}
338338

339339
// Augment the *new_value with the ttl time-stamp
340-
int32_t curtime;
340+
int64_t curtime;
341341
if (!DBWithTTL::GetCurrentTime(curtime).ok()) {
342342
Log(logger, "Error: Could not get current time to be attached internally "
343343
"to the new value.");
344344
return false;
345345
} else {
346346
char ts_string[ts_len];
347-
EncodeFixed32(ts_string, curtime);
347+
EncodeFixed32(ts_string, (int32_t)curtime);
348348
new_value->append(ts_string, ts_len);
349349
return true;
350350
}

0 commit comments

Comments
 (0)