Use gmtime_r() and localtime_r() instead of gmtime() and localtime().

This commit is contained in:
Todd C. Miller
2021-09-17 10:55:06 -06:00
parent fa71679b5a
commit 18f1884ddc
15 changed files with 135 additions and 166 deletions

View File

@@ -117,7 +117,7 @@ static int
sample_approval_check(char * const command_info[], char * const run_argv[],
char * const run_envp[], const char **errstr)
{
struct tm *tm;
struct tm tm;
time_t now;
int ret = 0;
debug_decl(sample_approval_check, SUDO_DEBUG_PLUGIN);
@@ -126,14 +126,14 @@ sample_approval_check(char * const command_info[], char * const run_argv[],
* Only approve requests that are within business hours,
* which are 9am - 5pm local time. Does not check holidays.
*/
if (time(&now) == -1 || (tm = localtime(&now)) == NULL)
if (time(&now) == -1 || localtime_r(&now, &tm) == NULL)
goto done;
if (tm->tm_wday < 1 || tm->tm_wday > 5) {
if (tm.tm_wday < 1 || tm.tm_wday > 5) {
/* bad weekday */
goto done;
}
if (tm->tm_hour < 9 || tm->tm_hour > 17 ||
(tm->tm_hour == 17 && tm->tm_min > 0)) {
if (tm.tm_hour < 9 || tm.tm_hour > 17 ||
(tm.tm_hour == 17 && tm.tm_min > 0)) {
/* bad hour */
goto done;
}