Skip to content

Commit 9263e19

Browse files
committed
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.
1 parent 2df8f2c commit 9263e19

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/iolog/iolog_timing.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ iolog_adjust_delay(struct timespec *delay, struct timespec *max_delay,
5555
{
5656
debug_decl(iolog_adjust_delay, SUDO_DEBUG_UTIL);
5757

58+
/* Avoid division by zero or negative delays. */
59+
if (scale_factor <= 0.0) {
60+
sudo_timespecclear(delay);
61+
debug_return;
62+
}
63+
5864
if (scale_factor != 1.0) {
5965
/* Order is important: we don't want to double the remainder. */
6066
const double seconds = (double)delay->tv_sec / scale_factor;

plugins/sudoers/sudoreplay.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ main(int argc, char *argv[])
287287
case 's':
288288
errno = 0;
289289
speed_factor = strtod(optarg, &ep);
290-
if (*ep != '\0' || errno != 0)
290+
if (*ep != '\0' || errno != 0 || speed_factor < 0.0)
291291
sudo_fatalx(U_("invalid speed factor: %s"), optarg);
292292
break;
293293
case 'V':
@@ -795,8 +795,7 @@ get_timing_record(struct replay_closure *closure)
795795

796796
if (nodelay) {
797797
/* Already waited, fire immediately. */
798-
timing->delay.tv_sec = 0;
799-
timing->delay.tv_nsec = 0;
798+
sudo_timespecclear(&timing->delay);
800799
} else {
801800
/* Adjust delay using speed factor and max_delay. */
802801
iolog_adjust_delay(&timing->delay, closure->max_delay,

0 commit comments

Comments
 (0)