Skip to content

Commit cb44ee1

Browse files
davidv1992rnijveld
authored andcommitted
Fix divide-by-zero when cookie length is 0.
1 parent 223fe7a commit cb44ee1

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

ntp-proto/src/source.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,9 @@ impl<Controller: SourceController<MeasurementDelay = NtpDuration>> NtpSource<Con
567567
// when requesting new cookies. We keep 350
568568
// bytes of margin for header, ids, extension
569569
// field headers and signature.
570-
let new_cookies = nts
571-
.cookies
572-
.gap()
573-
.min(((self.buffer.len() - 300) / cookie.len()).min(u8::MAX as usize) as u8);
570+
let new_cookies = nts.cookies.gap().min(
571+
((self.buffer.len() - 300) / (cookie.len().max(1))).min(u8::MAX as usize) as u8,
572+
);
574573
// Defence in depth, ensure we can get at least 1 new cookie.
575574
if new_cookies == 0 {
576575
warn!("NTS Cookie too large, resetting source. This may be a problem with the source");

0 commit comments

Comments
 (0)