rasdaemon: misc fixes
cover rasdaemon: misc fixes
These patches are for 3 issues found with covscan. None of them are likely to happen during regular use, but worth fixing anyway.
Signature · 1 line
Aristeu
PATCH 1/3 rasdaemon: ras-report: fix possible but unlikely file descriptor leak
Found with covscan.
ras-report.c +1 -1
@@ -768,7 +768,7 @@ int ras_report_mf_event(struct ras_events *ras, struct ras_mf_event *ev) done =1 ; mf_fail: -if (sockfd >0 ) +if (sockfd >=0 )close (sockfd);if (done)
PATCH 2/3 rasdaemon: mce-amd-smca: properly limit bank types
In reply to [email protected]Found with covscan.
mce-amd-smca.c +1 -1
@@ -584,7 +584,7 @@ static void decode_smca_error(struct mce_event *e)return ; } -if (bank_type >=MAX_NR_BANKS ) { +if (bank_type >=N_SMCA_BANK_TYPES ) {strcpy (e->mcastatus_msg,"Don't know how to decode this bank" );return ; }
PATCH 3/3 rasdaemon: ras-memory-failure-handler: handle localtime() failure correctly
In reply to [email protected]We could just have an empty string but keeping the format could prevent issues if someone is actually parsing this.
Found with covscan.
ras-memory-failure-handler.c +2 -0
@@ -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 )
RE: [PATCH 3/3] rasdaemon: ras-memory-failure-handler: handle localtime() failure correctly
Quoted 5 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Wednesday, July 20, 2022 9:40 AM
...
Quoted 7 lines
Subject: [PATCH 3/3] rasdaemon: ras-memory-failure-handler: handle
localtime()failure correctlyWe could just have an empty string but keeping the format could prevent issues if someone is actually parsing this.
Found with covscan.
...
Quoted 1 line
ras-memory-failure-handler.c +0
-0
...
ras-memory-failure-handler.c int ras_memory_failure_event_handler(struct trace_seq · line 153
Quoted 7 lines
ras-memory-failure-handler.c +2
-0@@ -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
Re: [PATCH 3/3] rasdaemon: ras-memory-failure-handler: handle localtime() failure correctly
Quoted 27 lines · Robert (Servers)
Quoted 3 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Wednesday, July 20, 2022 9:40 AM...
Quoted 7 lines
Subject: [PATCH 3/3] rasdaemon: ras-memory-failure-handler: handle
localtime()failure correctlyWe could just have an empty string but keeping the format could prevent issues if someone is actually parsing this.
Found with covscan....
Quoted 1 line
ras-memory-failure-handler.c +0
-0...
ras-memory-failure-handler.c int ras_memory_failure_event_handler(struct trace_seq · line 153
Quoted 7 lines
ras-memory-failure-handler.c +2
-0@@ -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.
Quoted 1 line
GMT does not match the lowercase %z format of +hhmm or -hhmm
Good catch, thanks
Quoted 2 lines
Returning the UNIX epoch might be safer, too:
1970-01-01 00:00:00 +0000
Agreed, v2 will follow
Signature · 1 line
Aristeu
PATCH v2 3/3 rasdaemon: ras-memory-failure-handler: handle localtime() failure correctly
In reply to Elliott, Robert (Servers)We could just have an empty string but keeping the format could prevent issues if someone is actually parsing this.
Found with covscan.
v2: fixed the timestamp as pointed by Robert Elliott
ras-memory-failure-handler.c +2 -0
@@ -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,"1970-01-01 00:00:00 +0000" ,sizeof (ev.timestamp));trace_seq_printf (s,"%s " , ev.timestamp);if (pevent_get_field_val (s, event,"pfn" , record, &val,1 ) <0 )