diff options
author | sam <sam@FreeBSD.org> | 2005-03-26 22:57:28 +0000 |
---|---|---|
committer | sam <sam@FreeBSD.org> | 2005-03-26 22:57:28 +0000 |
commit | 238c96d5e4adcfd0c9ba0dd40468937d5d2bb974 (patch) | |
tree | 82b0710bd52a695a610c99bd0bbd5023b7c7940e /sys/pci | |
parent | d2c3d0b002bb9dd56788d822f8687f3c1b06ca04 (diff) | |
download | FreeBSD-src-238c96d5e4adcfd0c9ba0dd40468937d5d2bb974.zip FreeBSD-src-238c96d5e4adcfd0c9ba0dd40468937d5d2bb974.tar.gz |
handle malloc failure and sk_vpd_prodname potentially being null for
other reasons
Noticed by: Coverity Prevent analysis tool
Reviewed by: bz, jmg
Diffstat (limited to 'sys/pci')
-rw-r--r-- | sys/pci/if_sk.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/sys/pci/if_sk.c b/sys/pci/if_sk.c index b7b9e47..44bd447 100644 --- a/sys/pci/if_sk.c +++ b/sys/pci/if_sk.c @@ -496,10 +496,12 @@ sk_vpd_read(sc) pos += sizeof(res); sc->sk_vpd_prodname = malloc(res.vr_len + 1, M_DEVBUF, M_NOWAIT); - for (i = 0; i < res.vr_len; i++) - sc->sk_vpd_prodname[i] = sk_vpd_readbyte(sc, i + pos); - sc->sk_vpd_prodname[i] = '\0'; - pos += i; + if (sc->sk_vpd_prodname != NULL) { + for (i = 0; i < res.vr_len; i++) + sc->sk_vpd_prodname[i] = sk_vpd_readbyte(sc, i + pos); + sc->sk_vpd_prodname[i] = '\0'; + } + pos += res.vr_len; sk_vpd_read_res(sc, &res, pos); @@ -1781,7 +1783,8 @@ skc_attach(dev) } /* Announce the product name and more VPD data if there. */ - device_printf(dev, "%s rev. %s(0x%x)\n", pname, revstr, sc->sk_rev); + device_printf(dev, "%s rev. %s(0x%x)\n", + pname != NULL ? pname : "<unknown>", revstr, sc->sk_rev); if (bootverbose) { if (sc->sk_vpd_readonly != NULL && |