diff --git a/src/DS/rds.c b/src/DS/rds.c index af3ae006fd..e4c827b8fe 100644 --- a/src/DS/rds.c +++ b/src/DS/rds.c @@ -846,8 +846,9 @@ struct oscap_source *ds_rds_create_source(struct oscap_source *sds_source, struc struct stat file_stat; if (stat(tailoring_filepath, &file_stat) == 0) { const size_t max_timestamp_len = 32; + struct tm result; tailoring_doc_timestamp = malloc(max_timestamp_len); - strftime(tailoring_doc_timestamp, max_timestamp_len, "%Y-%m-%dT%H:%M:%S", localtime(&file_stat.st_mtime)); + strftime(tailoring_doc_timestamp, max_timestamp_len, "%Y-%m-%dT%H:%M:%S", localtime_r(&file_stat.st_mtime, &result)); } } diff --git a/src/DS/sds.c b/src/DS/sds.c index c7c5c75b0d..15f5079c39 100644 --- a/src/DS/sds.c +++ b/src/DS/sds.c @@ -685,12 +685,13 @@ static int ds_sds_compose_add_component_internal(xmlDocPtr doc, xmlNodePtr datas struct stat file_stat; if (stat(filepath, &file_stat) == 0) { time_t mtime; + struct tm result; char *source_date_epoch = getenv("SOURCE_DATE_EPOCH"); if (source_date_epoch == NULL || (mtime = (time_t)strtoll(source_date_epoch, NULL, 10)) <= 0 || mtime > file_stat.st_mtime) mtime = file_stat.st_mtime; - strftime(file_timestamp, 32, "%Y-%m-%dT%H:%M:%S", localtime(&mtime)); + strftime(file_timestamp, 32, "%Y-%m-%dT%H:%M:%S", localtime_r(&mtime, &result)); } else { oscap_seterr(OSCAP_EFAMILY_GLIBC, "Could not find file %s: %s.", filepath, strerror(errno)); // Return positive number, indicating less severe problem. @@ -796,7 +797,7 @@ static int ds_sds_compose_catalog_has_uri(xmlDocPtr doc, xmlNodePtr catalog, con return -1; } - + xmlXPathObjectPtr xpathObj = xmlXPathEvalExpression( BAD_CAST expression, xpathCtx); diff --git a/src/OVAL/oval_component.c b/src/OVAL/oval_component.c index f42236a682..c8e577cf88 100644 --- a/src/OVAL/oval_component.c +++ b/src/OVAL/oval_component.c @@ -1869,9 +1869,10 @@ static long unsigned int _comp_sec(int year, int month, int day, int hour, int m { time_t t; struct tm *ts; + struct tm result; t = time(NULL); - ts = localtime(&t); + ts = localtime_r(&t, &result); ts->tm_year = year - 1900; ts->tm_mon = month - 1; @@ -1881,7 +1882,7 @@ static long unsigned int _comp_sec(int year, int month, int day, int hour, int m ts->tm_sec = second; ts->tm_isdst = -1; t = mktime(ts); - ts = localtime(&t); + ts = localtime_r(&t, &result); if (ts->tm_isdst == 1) t -= 3600; @@ -1969,9 +1970,10 @@ static long unsigned int _parse_fmt_sse(char *dt) { time_t t; struct tm *ts; + struct tm result; t = (time_t) atol(dt); - ts = localtime(&t); + ts = localtime_r(&t, &result); if (ts->tm_isdst == 1) t -= 3600; diff --git a/src/OVAL/oval_generator.c b/src/OVAL/oval_generator.c index e423a9551d..bea75b8732 100644 --- a/src/OVAL/oval_generator.c +++ b/src/OVAL/oval_generator.c @@ -155,7 +155,8 @@ void oval_generator_update_timestamp(struct oval_generator *generator) struct tm *lt; time(&et); - lt = localtime(&et); + struct tm localtime_state; + lt = localtime_r(&et, &localtime_state); int timestamp_size = snprintf(NULL, 0, "%4d-%02d-%02dT%02d:%02d:%02d", 1900 + lt->tm_year, 1 + lt->tm_mon, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec); if (timestamp_size < 0) { diff --git a/src/OVAL/probes/unix/process58_probe.c b/src/OVAL/probes/unix/process58_probe.c index 0b47230714..7a5df13eb9 100644 --- a/src/OVAL/probes/unix/process58_probe.c +++ b/src/OVAL/probes/unix/process58_probe.c @@ -477,6 +477,7 @@ static int read_process(SEXP_t *cmd_ent, SEXP_t *pid_ent, probe_ctx *ctx) DIR *d; struct dirent *ent; oval_schema_version_t oval_version; + struct tm result; const char *prefix = getenv("OSCAP_PROBE_ROOT"); snprintf(buf, PATH_MAX, "%s/proc", prefix ? prefix : ""); @@ -605,11 +606,11 @@ static int read_process(SEXP_t *cmd_ent, SEXP_t *pid_ent, probe_ctx *ctx) // Calculate the start time s_time = time(NULL); - now = localtime(&s_time); + now = localtime_r(&s_time, &result); tyear = now->tm_year; tday = now->tm_yday; s_time = boot + (start / ticks); - proc = localtime(&s_time); + proc = localtime_r(&s_time, &result); // Select format based on how long we've been running // @@ -729,6 +730,7 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx) int err = 1; DIR *d; struct dirent *ent; + struct tm result; d = opendir("/proc"); if (d == NULL) @@ -784,13 +786,13 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx) // Get the start time s_time = time(NULL); - now = localtime(&s_time); + now = localtime_r(&s_time, &result); tyear = now->tm_year; tday = now->tm_yday; // Get current time s_time = psinfo->pr_start.tv_sec; - proc = localtime(&s_time); + proc = localtime_r(&s_time, &result); // Select format based on how long we've been running // diff --git a/src/OVAL/probes/unix/process_probe.c b/src/OVAL/probes/unix/process_probe.c index 8543b15e12..81dff1f709 100644 --- a/src/OVAL/probes/unix/process_probe.c +++ b/src/OVAL/probes/unix/process_probe.c @@ -200,6 +200,7 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx) int err = 1; DIR *d; struct dirent *ent; + struct tm result; d = opendir("/proc"); if (d == NULL) @@ -299,11 +300,11 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx) // Calculate the start time s_time = time(NULL); - now = localtime(&s_time); + now = localtime_r(&s_time, &result); tyear = now->tm_year; tday = now->tm_yday; s_time = boot + (start / ticks); - proc = localtime(&s_time); + proc = localtime_r(&s_time, &result); // Select format based on how long we've been running // @@ -439,13 +440,13 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx) // Get the start time s_time = time(NULL); - now = localtime(&s_time); + now = localtime_r(&s_time, &result); tyear = now->tm_year; tday = now->tm_yday; // Get current time s_time = psinfo->pr_start.tv_sec; - proc = localtime(&s_time); + proc = localtime_r(&s_time, &result); // Select format based on how long we've been running // @@ -595,7 +596,8 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx) fmt = "%H:%M:%S"; } - struct tm *loc_time = localtime(&start_time); + struct tm result; + struct tm *loc_time = localtime_r(&start_time, &result); strftime(start_buf, sizeof(start_buf), fmt, loc_time); switch(proc->ki_tdev) { @@ -604,7 +606,7 @@ static int read_process(SEXP_t *cmd_ent, probe_ctx *ctx) break; default: snprintf(tty_buf, sizeof(tty_buf), "%ld", proc->ki_tdev); - r.tty = tty_buf; + r.tty = tty_buf; break; } diff --git a/src/XCCDF/item.c b/src/XCCDF/item.c index 9d656b7abe..480e45cb73 100644 --- a/src/XCCDF/item.c +++ b/src/XCCDF/item.c @@ -542,7 +542,8 @@ xmlNode *xccdf_status_to_dom(struct xccdf_status *status, xmlDoc *doc, xmlNode * time_t date_time = xccdf_status_get_date(status); if (date_time) { - struct tm *date = localtime(&date_time); + struct tm result; + struct tm *date = localtime_r(&date_time, &result); /* "YYYY-DD-MM" */ int date_len = snprintf(NULL, 0, "%04d-%02d-%02d", date->tm_year + 1900, date->tm_mon + 1, date->tm_mday); if (date_len < 0) { diff --git a/src/XCCDF/result.c b/src/XCCDF/result.c index 83456f8133..9117bd22a1 100644 --- a/src/XCCDF/result.c +++ b/src/XCCDF/result.c @@ -1770,11 +1770,12 @@ static inline const char *_get_timestamp(void) static char timestamp[] = "yyyy-mm-ddThh:mm:ss+zz:zz"; time_t tm; struct tm *lt; + struct tm result; int tz_diff; char tz_sign; tm = time(NULL); - lt = localtime(&tm); + lt = localtime_r(&tm, &result); if (!lt) return NULL; diff --git a/utils/oscap-info.c b/utils/oscap-info.c index a459d9d6a1..a707ee6e4e 100644 --- a/utils/oscap-info.c +++ b/utils/oscap-info.c @@ -76,10 +76,11 @@ struct oscap_module OSCAP_INFO_MODULE = { static void print_time(const char *file) { struct stat buffer; + struct tm result; char timeStr[ 100 ] = ""; if(!stat(file, &buffer)) { - strftime(timeStr, 100, "%Y-%m-%dT%H:%M:%S", localtime(&buffer.st_mtime)); + strftime(timeStr, 100, "%Y-%m-%dT%H:%M:%S", localtime_r(&buffer.st_mtime, &result)); printf("Imported: %s\n", timeStr); } } @@ -90,7 +91,8 @@ static inline void _print_xccdf_status(struct xccdf_status *status, const char * printf("%sStatus: %s\n", prefix, xccdf_status_type_to_text(xccdf_status_get_status(status))); const time_t date_time = xccdf_status_get_date(status); if (date_time != 0) { - struct tm *date = localtime(&date_time); + struct tm result; + struct tm *date = localtime_r(&date_time, &result); char date_str[] = "YYYY-DD-MM"; int ret = snprintf(date_str, sizeof(date_str), "%04d-%02d-%02d", date->tm_year + 1900, date->tm_mon + 1, date->tm_mday); if (ret < 0) {