Skip to content

Commit 4c3101c

Browse files
committed
add tat_us negative check
1 parent d5ebdec commit 4c3101c

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/gcra.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ void gcraCommand(client *c) {
142142
addReplyError(c, "Invalid GCRA key");
143143
return;
144144
}
145+
if (tat_us <= 0) {
146+
addReplyError(c, "Negative time is invalid value for GCRA");
147+
return;
148+
}
145149
} else {
146150
tat_us = now;
147151
}
@@ -178,7 +182,6 @@ void gcraCommand(client *c) {
178182
* Hence for multiple requests we multiple by their number. */
179183
long long increment_us = emission_interval_us * num_requests;
180184

181-
long long ttl_us;
182185
long long base_us = (now > tat_us) ? now : tat_us;
183186
if (LLONG_MAX - base_us < increment_us) {
184187
addReplyError(c, "GCRA limiting uses microsecond accuracy. Combination of period, requests_per_period and num_requests would cause an overflow");
@@ -191,7 +194,8 @@ void gcraCommand(client *c) {
191194
* time we ask (i.e now) we allow the request, otherwise we limit it and
192195
* calculate after how much time the user should retry. */
193196
long long allow_at = new_tat_us - variance_us;
194-
long long diff_us = now - allow_at; // variance - increment
197+
long long diff_us = now - allow_at;
198+
long long ttl_us;
195199
if (diff_us < 0) {
196200
limited = 1;
197201
/* NOTE: if increment is more than variance, then number of requests is

0 commit comments

Comments
 (0)