Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/DS/rds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/DS/sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions src/OVAL/oval_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/OVAL/oval_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions src/OVAL/probes/unix/process58_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 : "");
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
//
Expand Down
14 changes: 8 additions & 6 deletions src/OVAL/probes/unix/process_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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
//
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/XCCDF/item.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/XCCDF/result.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions utils/oscap-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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) {
Expand Down
Loading