Fix division by zero during send hold time calculation when hold timer
set to zero.
Fix possible overflow in the send hold time calculation.
Add minimum value for send hold time option as per RFC 9687 section 4.4.
Reported-By: lzx0xf1@gmail.com
Target: patch
if (cf->keepalive_time > (cf->hold_time / 2))
log(L_WARN "Keepalive time should be at most 1/2 of hold time");
+ if ((cf->send_hold_time > 0) && (cf->send_hold_time < cf->hold_time))
+ cf_error("Send hold time must be zero or at least hold time");
+
if (cf->min_hold_time > cf->hold_time)
cf_error("Min hold time (%u) exceeds hold time (%u)",
cf->min_hold_time, cf->hold_time);
/* Compute effective hold and keepalive times */
uint hold_time = MIN(hold, p->cf->hold_time);
+ uint base_hold_time = p->cf->hold_time ?: 1;
+
uint keepalive_time = p->cf->keepalive_time ?
- (p->cf->keepalive_time * hold_time / p->cf->hold_time) :
+ (p->cf->keepalive_time * hold_time / base_hold_time) :
hold_time / 3;
uint send_hold_time = (p->cf->send_hold_time >= 0) ?
- (p->cf->send_hold_time * hold_time / p->cf->hold_time) :
+ ((u64) p->cf->send_hold_time * hold_time / base_hold_time) :
2 * hold_time;
/* Keepalive time might be rounded down to zero */