From 9263e19f7e5a1f08c126cd80b87cca3a4d3c9fb1 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Thu, 21 Aug 2025 12:40:28 -0600 Subject: [PATCH] iolog_adjust_delay: avoid division by zero Fixes a problem in sudoreplay where a speed factor of 0 or less would result in a negative delay value that caused a hang during playback. Bug #1078. --- lib/iolog/iolog_timing.c | 6 ++++++ plugins/sudoers/sudoreplay.c | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/iolog/iolog_timing.c b/lib/iolog/iolog_timing.c index c933b4ca8..4fba08d62 100644 --- a/lib/iolog/iolog_timing.c +++ b/lib/iolog/iolog_timing.c @@ -55,6 +55,12 @@ iolog_adjust_delay(struct timespec *delay, struct timespec *max_delay, { debug_decl(iolog_adjust_delay, SUDO_DEBUG_UTIL); + /* Avoid division by zero or negative delays. */ + if (scale_factor <= 0.0) { + sudo_timespecclear(delay); + debug_return; + } + if (scale_factor != 1.0) { /* Order is important: we don't want to double the remainder. */ const double seconds = (double)delay->tv_sec / scale_factor; diff --git a/plugins/sudoers/sudoreplay.c b/plugins/sudoers/sudoreplay.c index d4aa2662c..5f81111a9 100644 --- a/plugins/sudoers/sudoreplay.c +++ b/plugins/sudoers/sudoreplay.c @@ -287,7 +287,7 @@ main(int argc, char *argv[]) case 's': errno = 0; speed_factor = strtod(optarg, &ep); - if (*ep != '\0' || errno != 0) + if (*ep != '\0' || errno != 0 || speed_factor < 0.0) sudo_fatalx(U_("invalid speed factor: %s"), optarg); break; case 'V': @@ -795,8 +795,7 @@ get_timing_record(struct replay_closure *closure) if (nodelay) { /* Already waited, fire immediately. */ - timing->delay.tv_sec = 0; - timing->delay.tv_nsec = 0; + sudo_timespecclear(&timing->delay); } else { /* Adjust delay using speed factor and max_delay. */ iolog_adjust_delay(&timing->delay, closure->max_delay,