2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 01:49:11 +00:00

Format T_TIMESPEC as "%d.%d" instead of "%.1f"

This fixes the display of the timeout values in the "sudo -V" output
on systems without a C99-compliant snprintf().  The snprintf()
replacement sudo ships with does not support floating point.
This commit is contained in:
Todd C. Miller 2025-01-05 14:11:18 -07:00
parent 7c121ff834
commit 01b1410d61
3 changed files with 10 additions and 8 deletions

View File

@ -191,11 +191,11 @@ struct sudo_defs_types sudo_defs_table[] = {
NULL,
}, {
"timestamp_timeout", T_TIMESPEC|T_BOOL,
N_("Authentication timestamp timeout: %.1f minutes"),
N_("Authentication timestamp timeout: %d.%d minutes"),
NULL,
}, {
"passwd_timeout", T_TIMESPEC|T_BOOL,
N_("Password prompt timeout: %.1f minutes"),
N_("Password prompt timeout: %d.%d minutes"),
NULL,
}, {
"passwd_tries", T_UINT,

View File

@ -115,10 +115,10 @@ loglinelen
"Length at which to wrap log file lines (0 for no wrap): %u"
timestamp_timeout
T_TIMESPEC|T_BOOL
"Authentication timestamp timeout: %.1f minutes"
"Authentication timestamp timeout: %d.%d minutes"
passwd_timeout
T_TIMESPEC|T_BOOL
"Password prompt timeout: %.1f minutes"
"Password prompt timeout: %d.%d minutes"
passwd_tries
T_UINT
"Number of tries to enter a password: %u"

View File

@ -130,10 +130,12 @@ dump_defaults(void)
sudo_printf(SUDO_CONV_INFO_MSG, "\n");
break;
case T_TIMESPEC: {
/* display timespec in minutes as a double */
double d = (double)cur->sd_un.tspec.tv_sec +
((double)cur->sd_un.tspec.tv_nsec / 1000000000.0);
sudo_printf(SUDO_CONV_INFO_MSG, desc, d / 60.0);
/* display timespec in minutes and 10ths of a minute */
const int min = cur->sd_un.tspec.tv_sec / 60;
int decimin =
(((cur->sd_un.tspec.tv_sec % 60) * 10) + 30) / 60;
decimin += cur->sd_un.tspec.tv_nsec / 100000000;
sudo_printf(SUDO_CONV_INFO_MSG, desc, min, decimin);
sudo_printf(SUDO_CONV_INFO_MSG, "\n");
break;
}