Skip to content

Commit e3735f7

Browse files
cosmo0920edsiper
authored andcommitted
in_winevtlog: Address coderabbitai comments
Signed-off-by: Hiroshi Hatake <hiroshi@chronosphere.io>
1 parent 3b91773 commit e3735f7

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

plugins/in_winevtlog/in_winevtlog.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,31 @@ static int in_winevtlog_init(struct flb_input_instance *in,
199199
}
200200
ctx->backoff.multiplier_x1000 = (DWORD)(mult * 1000.0);
201201

202+
/* normalize base/max/jitter/retries to sane ranges */
202203
if (ctx->backoff.base_ms == 0) {
203204
ctx->backoff.base_ms = 500;
204205
}
205-
206206
if (ctx->backoff.max_ms == 0) {
207207
ctx->backoff.max_ms = 30000;
208208
}
209-
210209
if (ctx->backoff.jitter_pct == 0) {
211210
ctx->backoff.jitter_pct = 20;
212211
}
213-
214212
if (ctx->backoff.max_retries == 0) {
215213
ctx->backoff.max_retries = 8;
216214
}
217215

216+
/* clamp out-of-range values, protecting against negative INT written into DWORD */
217+
if (ctx->backoff.base_ms > 3600000U) { /* cap at 1 hour */
218+
ctx->backoff.base_ms = 3600000U;
219+
}
220+
if (ctx->backoff.max_ms > 86400000U) { /* cap at 24 hours */
221+
ctx->backoff.max_ms = 86400000U;
222+
}
223+
if (ctx->backoff.jitter_pct > 100U) { /* jitter as percentage */
224+
ctx->backoff.jitter_pct = 100U;
225+
}
226+
/* ensure ordering */
218227
if (ctx->backoff.max_ms < ctx->backoff.base_ms) {
219228
flb_plg_warn(in, "reconnect.max_ms < reconnect.base_ms, swapping values");
220229
tmp_ms = ctx->backoff.base_ms;

plugins/in_winevtlog/winevtlog.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,13 @@ static int winevtlog_next(struct winevtlog_channel *ch, int hit_threshold)
619619
status = GetLastError();
620620
if (status == ERROR_CANCELLED) {
621621
if (ch->cancelled_by_us) {
622-
/* Conmsume this flag and return early */
622+
/* Consume this flag and return early */
623623
ch->cancelled_by_us = FALSE;
624624
return FLB_FALSE;
625625
}
626626
ch->reconnect_needed = TRUE;
627627
ch->last_error = status;
628-
flb_debug("[in_winevtlog] subscription cancelled unexpectedly (err=%lu), will reconnect", status);
628+
flb_warn("[in_winevtlog] subscription cancelled unexpectedly (err=%lu), will reconnect", status);
629629
return FLB_FALSE;
630630
}
631631
if (status != ERROR_NO_MORE_ITEMS) {
@@ -673,6 +673,7 @@ static DWORD calc_backoff_ms(struct winevtlog_channel *ch, const struct winevtlo
673673
LONG span = 0;
674674
LONG delta = 0;
675675
LONG with_jitter = 0;
676+
DWORD jitter = 0;
676677
double mult = (double)cfg->multiplier_x1000 / 1000.0;
677678
double t = (double)cfg->base_ms;
678679

@@ -681,13 +682,11 @@ static DWORD calc_backoff_ms(struct winevtlog_channel *ch, const struct winevtlo
681682
if (t >= (double)cfg->max_ms) { t = (double)cfg->max_ms; break; }
682683
}
683684
ms = (DWORD)((t > (double)cfg->max_ms) ? cfg->max_ms : t);
684-
/* ±jitter% */
685-
span = (LONG)((ms * cfg->jitter_pct) / 100);
685+
/* ±jitter% (clamped 0..100) */
686+
jitter = cfg->jitter_pct > 100 ? 100 : cfg->jitter_pct;
687+
span = (LONG)((ms * jitter) / 100);
686688
delta = (LONG)(prng16(&ch->prng_state) % (2 * span + 1)) - span;
687689
with_jitter = (LONG)ms + delta;
688-
if (with_jitter < 0) {
689-
with_jitter = 0;
690-
}
691690
return (DWORD)with_jitter;
692691
}
693692

0 commit comments

Comments
 (0)