Message ID | 20220720143957.977427150@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | rasdaemon: misc fixes | expand |
> -----Original Message----- > From: arozansk@redhat.com <arozansk@redhat.com> > Sent: Wednesday, July 20, 2022 9:40 AM ... > Subject: [PATCH 3/3] rasdaemon: ras-memory-failure-handler: handle > localtime() failure correctly > > We could just have an empty string but keeping the format could prevent > issues if someone is actually parsing this. > Found with covscan. > ... > diff --git a/ras-memory-failure-handler.c b/ras-memory-failure-handler.c ... > @@ -148,6 +148,8 @@ int ras_memory_failure_event_handler(struct trace_seq > *s, > if (tm) > strftime(ev.timestamp, sizeof(ev.timestamp), > "%Y-%m-%d %H:%M:%S %z", tm); > + else > + strncpy(ev.timestamp, "0000-00-00 00:00:00 GMT", sizeof(ev.timestamp)); Per man strftime: %z The +hhmm or -hhmm numeric timezone (that is, the hour and minute offset from UTC). (SU) %Z The timezone name or abbreviation. GMT does not match the lowercase %z format of +hhmm or -hhmm Returning the UNIX epoch might be safer, too: 1970-01-01 00:00:00 +0000
On Wed, Jul 20, 2022 at 03:33:49PM +0000, Elliott, Robert (Servers) wrote: > > -----Original Message----- > > From: arozansk@redhat.com <arozansk@redhat.com> > > Sent: Wednesday, July 20, 2022 9:40 AM > ... > > Subject: [PATCH 3/3] rasdaemon: ras-memory-failure-handler: handle > > localtime() failure correctly > > > > We could just have an empty string but keeping the format could prevent > > issues if someone is actually parsing this. > > Found with covscan. > > > ... > > diff --git a/ras-memory-failure-handler.c b/ras-memory-failure-handler.c > ... > > @@ -148,6 +148,8 @@ int ras_memory_failure_event_handler(struct trace_seq > > *s, > > if (tm) > > strftime(ev.timestamp, sizeof(ev.timestamp), > > "%Y-%m-%d %H:%M:%S %z", tm); > > + else > > + strncpy(ev.timestamp, "0000-00-00 00:00:00 GMT", sizeof(ev.timestamp)); > > > Per man strftime: > %z The +hhmm or -hhmm numeric timezone (that is, the hour and minute offset from UTC). (SU) > %Z The timezone name or abbreviation. > > GMT does not match the lowercase %z format of +hhmm or -hhmm Good catch, thanks > Returning the UNIX epoch might be safer, too: > 1970-01-01 00:00:00 +0000 Agreed, v2 will follow
diff --git a/ras-memory-failure-handler.c b/ras-memory-failure-handler.c index 9941e68..9574141 100644 --- a/ras-memory-failure-handler.c +++ b/ras-memory-failure-handler.c @@ -148,6 +148,8 @@ int ras_memory_failure_event_handler(struct trace_seq *s, if (tm) strftime(ev.timestamp, sizeof(ev.timestamp), "%Y-%m-%d %H:%M:%S %z", tm); + else + strncpy(ev.timestamp, "0000-00-00 00:00:00 GMT", sizeof(ev.timestamp)); trace_seq_printf(s, "%s ", ev.timestamp); if (pevent_get_field_val(s, event, "pfn", record, &val, 1) < 0)
We could just have an empty string but keeping the format could prevent issues if someone is actually parsing this. Found with covscan. Signed-off-by: Aristeu Rozanski <arozansk@redhat.com>