mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 01:49:11 +00:00
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.
This commit is contained in:
parent
2df8f2ca9e
commit
9263e19f7e
@ -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;
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user