From 01b1410d615e3b83851290a9134fcd409003abd0 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sun, 5 Jan 2025 14:11:18 -0700 Subject: [PATCH] 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. --- plugins/sudoers/def_data.c | 4 ++-- plugins/sudoers/def_data.in | 4 ++-- plugins/sudoers/defaults.c | 10 ++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/sudoers/def_data.c b/plugins/sudoers/def_data.c index 0014b15c0..fd04b2195 100644 --- a/plugins/sudoers/def_data.c +++ b/plugins/sudoers/def_data.c @@ -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, diff --git a/plugins/sudoers/def_data.in b/plugins/sudoers/def_data.in index fa0050de9..62be675fc 100644 --- a/plugins/sudoers/def_data.in +++ b/plugins/sudoers/def_data.in @@ -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" diff --git a/plugins/sudoers/defaults.c b/plugins/sudoers/defaults.c index 0488f5e34..880a92057 100644 --- a/plugins/sudoers/defaults.c +++ b/plugins/sudoers/defaults.c @@ -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; }