Skip to content

Commit c71c434

Browse files
committed
dp-hw.c: fix incorrect error handling of efidp_node_size() invocations
One of our analysis tools noticed the following error: Error: OVERRUN (CWE-119): efivar-38/src/dp-hw.c:64: return_constant: Function call "efidp_node_size(dp)" may return -1. efivar-38/src/dp-hw.c:64: overrun-buffer-arg: Calling "format_hex_helper" with "(uint8_t *)dp + 4" and "efidp_node_size(dp) - 4L" is suspicious because of the very large index, 18446744073709551611. The index may be due to a negative parameter being interpreted as unsigned. # 62| format(buf, size, off, "Hardware", # 63| "HardwarePath(%d,", dp->subtype); # 64|-> format_hex(buf, size, off, "Hardware", (uint8_t *)dp+4, # 65| efidp_node_size(dp)-4); # 66| format(buf, size, off, "Hardware", ")"); This patch adds error checking to that use of efidp_node_size(). Resolves: RHEL-27676 Signed-off-by: Peter Jones <[email protected]>
1 parent 72b3093 commit c71c434

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/dp-hw.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,20 @@ _format_hw_dn(unsigned char *buf, size_t size, const_efidp dp)
5858
format(buf, size, off, "BMC", "BMC(%d,0x%"PRIx64")",
5959
dp->bmc.interface_type, dp->bmc.base_addr);
6060
break;
61-
default:
61+
default: {
62+
ssize_t sz = efidp_node_size(dp);
63+
64+
if (SUB(sz, 4, &sz) ||
65+
sz < 0) {
66+
efi_error("bad DP node size");
67+
return -1;
68+
}
6269
format(buf, size, off, "Hardware",
6370
"HardwarePath(%d,", dp->subtype);
64-
format_hex(buf, size, off, "Hardware", (uint8_t *)dp+4,
65-
efidp_node_size(dp)-4);
71+
format_hex(buf, size, off, "Hardware", (uint8_t *)dp+4, sz);
6672
format(buf, size, off, "Hardware", ")");
6773
break;
74+
}
6875
}
6976
return off;
7077
}

0 commit comments

Comments
 (0)