Skip to contentSkip to conversation

rasdaemon: misc fixes

PATCH In review [email protected] 2 participants 7 messages Jul 20, 2022 EDAC-core

lore
Share & tools
lore
#1 lore raw

PATCH 1/3 rasdaemon: ras-report: fix possible but unlikely file descriptor leak

Found with covscan.

ras-report.c +1 -1
index ea3a9b6..0088745 100644
@@ -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)
#2 lore raw

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
index f3379fc..27ca8aa 100644
@@ -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;
 	}
#3 lore raw

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
index 9941e68..9574141 100644
@@ -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)
#4 lore raw

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 correctly

We 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
#5 lore raw

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 correctly

We 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
#6 lore raw

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
index 9941e68..9574141 100644
@@ -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)