Skip to content

Commit 01b1410

Browse files
committed
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.
1 parent 7c121ff commit 01b1410

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

plugins/sudoers/def_data.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ struct sudo_defs_types sudo_defs_table[] = {
191191
NULL,
192192
}, {
193193
"timestamp_timeout", T_TIMESPEC|T_BOOL,
194-
N_("Authentication timestamp timeout: %.1f minutes"),
194+
N_("Authentication timestamp timeout: %d.%d minutes"),
195195
NULL,
196196
}, {
197197
"passwd_timeout", T_TIMESPEC|T_BOOL,
198-
N_("Password prompt timeout: %.1f minutes"),
198+
N_("Password prompt timeout: %d.%d minutes"),
199199
NULL,
200200
}, {
201201
"passwd_tries", T_UINT,

plugins/sudoers/def_data.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ loglinelen
115115
"Length at which to wrap log file lines (0 for no wrap): %u"
116116
timestamp_timeout
117117
T_TIMESPEC|T_BOOL
118-
"Authentication timestamp timeout: %.1f minutes"
118+
"Authentication timestamp timeout: %d.%d minutes"
119119
passwd_timeout
120120
T_TIMESPEC|T_BOOL
121-
"Password prompt timeout: %.1f minutes"
121+
"Password prompt timeout: %d.%d minutes"
122122
passwd_tries
123123
T_UINT
124124
"Number of tries to enter a password: %u"

plugins/sudoers/defaults.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ dump_defaults(void)
130130
sudo_printf(SUDO_CONV_INFO_MSG, "\n");
131131
break;
132132
case T_TIMESPEC: {
133-
/* display timespec in minutes as a double */
134-
double d = (double)cur->sd_un.tspec.tv_sec +
135-
((double)cur->sd_un.tspec.tv_nsec / 1000000000.0);
136-
sudo_printf(SUDO_CONV_INFO_MSG, desc, d / 60.0);
133+
/* display timespec in minutes and 10ths of a minute */
134+
const int min = cur->sd_un.tspec.tv_sec / 60;
135+
int decimin =
136+
(((cur->sd_un.tspec.tv_sec % 60) * 10) + 30) / 60;
137+
decimin += cur->sd_un.tspec.tv_nsec / 100000000;
138+
sudo_printf(SUDO_CONV_INFO_MSG, desc, min, decimin);
137139
sudo_printf(SUDO_CONV_INFO_MSG, "\n");
138140
break;
139141
}

0 commit comments

Comments
 (0)