Skip to content

Commit

Permalink
rasdaemon: check if sscanf() processed all arguments on dev_name
Browse files Browse the repository at this point in the history
Ensure that all arguments are parsed by sscanf() when dealing
with dev_name.

Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
mchehab committed Nov 19, 2024
1 parent cd14914 commit 48f5a5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 13 additions & 12 deletions ras-aer-handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,19 @@ int ras_aer_event_handler(struct trace_seq *s,
* number, byte 16[7:3] is device number, byte 16[2:0] is
* function number
*/
sscanf(ev.dev_name, "%x:%x:%x.%x", &seg, &bus, &dev, &fn);

sel_data[1] = seg & 0xff;
sel_data[2] = (seg & 0xff00) >> 8;
sel_data[3] = bus;
sel_data[4] = (((dev & 0x1f) << 3) | (fn & 0x7));

snprintf(ipmi_add_sel, sizeof(ipmi_add_sel),
"ipmitool raw 0x0a 0x44 0x00 0x00 0xc0 0x00 0x00 0x00 0x00 0x3a 0xcd 0x00 0xc0 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
sel_data[0], sel_data[1], sel_data[2], sel_data[3], sel_data[4]);

rc = system(ipmi_add_sel);
rc = sscanf(ev.dev_name, "%x:%x:%x.%x", &seg, &bus, &dev, &fn);
if (rc == 4) {
sel_data[1] = seg & 0xff;
sel_data[2] = (seg & 0xff00) >> 8;
sel_data[3] = bus;
sel_data[4] = (((dev & 0x1f) << 3) | (fn & 0x7));

snprintf(ipmi_add_sel, sizeof(ipmi_add_sel),
"ipmitool raw 0x0a 0x44 0x00 0x00 0xc0 0x00 0x00 0x00 0x00 0x3a 0xcd 0x00 0xc0 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
sel_data[0], sel_data[1], sel_data[2], sel_data[3], sel_data[4]);

rc = system(ipmi_add_sel);
}
if (rc)
log(SYSLOG, LOG_WARNING, "Failed to execute ipmitool\n");
#endif
Expand Down
4 changes: 3 additions & 1 deletion unified-sel.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ int openbmc_unified_sel_log(uint64_t severity, const char *dev_name, uint64_t st
{
int bus, dev, dev_fn, fn;

sscanf(dev_name, "%*x:%x:%x.%x", &bus, &dev, &fn);
if (sscanf(dev_name, "%*x:%x:%x.%x", &bus, &dev, &fn) != 3)
return -1;

dev_fn = (((dev & 0x1f) << 3) | (fn & 0x7));

/*
Expand Down

0 comments on commit 48f5a5d

Please sign in to comment.