jedec_dimm: Use correct string length when populating sc->slotid_str

Don't limit the copy to the size of the target string *pointer* (always
4 on 32-bit / 8 on 64-bit). Instead, just use strdup().

Reported by:	Coverity
CID:		1386912
Reviewed by:	cem, imp
MFC after:	1 week
This commit is contained in:
Ravi Pokala 2018-03-22 06:31:05 +00:00
parent 27cd06b391
commit 4754f6ad41

View File

@ -341,10 +341,7 @@ jedec_dimm_attach(device_t dev)
if (resource_string_value(device_get_name(dev), device_get_unit(dev),
"slotid", &slotid_str) == 0) {
if (slotid_str != NULL) {
sc->slotid_str = malloc(strlen(slotid_str) + 1,
M_DEVBUF, (M_WAITOK | M_ZERO));
strlcpy(sc->slotid_str, slotid_str,
sizeof(sc->slotid_str));
sc->slotid_str = strdup(slotid_str, M_DEVBUF);
SYSCTL_ADD_STRING(ctx, children, OID_AUTO, "slotid",
CTLFLAG_RD | CTLFLAG_MPSAFE, sc->slotid_str, 0,
"DIMM Slot Identifier");