Date: Thu, 9 Apr 2020 18:17:07 +0000 (UTC) From: David Bright <dab@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r359751 - in stable/12/sbin/nvmecontrol: . modules/wdc Message-ID: <202004091817.039IH7sr080044@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dab Date: Thu Apr 9 18:17:07 2020 New Revision: 359751 URL: https://svnweb.freebsd.org/changeset/base/359751 Log: MFC r359562: Fix various Coverity-detected errors in nvmecontrol This fixes several Coverity-detected errors in nvmecontrol. While in here, a couple additional errors with shift/mask confusion that were not diagnosed by Coverity are also fixed. CIDs addressed: 1040299, 1040300, 1403972, 1403973, 1403985, 1403988, 1403990, 1404374, 1404427, 1404469, 1404510, 1404534, 1418118 CID 1403657 (resource leak of shared library handle) was marked "intentional" in the Coverity scan database. Sponsored by: Dell EMC Isilon Modified: stable/12/sbin/nvmecontrol/firmware.c stable/12/sbin/nvmecontrol/identify.c stable/12/sbin/nvmecontrol/logpage.c stable/12/sbin/nvmecontrol/modules/wdc/wdc.c stable/12/sbin/nvmecontrol/nsid.c stable/12/sbin/nvmecontrol/passthru.c stable/12/sbin/nvmecontrol/power.c stable/12/sbin/nvmecontrol/reset.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sbin/nvmecontrol/firmware.c ============================================================================== --- stable/12/sbin/nvmecontrol/firmware.c Thu Apr 9 16:24:57 2020 (r359750) +++ stable/12/sbin/nvmecontrol/firmware.c Thu Apr 9 18:17:07 2020 (r359751) @@ -151,6 +151,7 @@ read_image_file(const char *path, void **buf, int32_t errx(1, "error reading '%s' (read %d bytes, requested %d bytes)", path, *size, filesize); + close(fd); } static void @@ -188,6 +189,7 @@ update_firmware(int fd, uint8_t *payload, int32_t payl resid -= size; off += size; } + free(chunk); } static int Modified: stable/12/sbin/nvmecontrol/identify.c ============================================================================== --- stable/12/sbin/nvmecontrol/identify.c Thu Apr 9 16:24:57 2020 (r359750) +++ stable/12/sbin/nvmecontrol/identify.c Thu Apr 9 18:17:07 2020 (r359751) @@ -94,7 +94,7 @@ print_namespace(struct nvme_namespace_data *nsdata) NVME_NS_DATA_DPC_PIT3_MASK) ? "Type 3, " : "", ((nsdata->dpc >> NVME_NS_DATA_DPC_PIT2_SHIFT) & NVME_NS_DATA_DPC_PIT2_MASK) ? "Type 2, " : "", - ((nsdata->dpc >> NVME_NS_DATA_DPC_PIT2_MASK) & + ((nsdata->dpc >> NVME_NS_DATA_DPC_PIT1_SHIFT) & NVME_NS_DATA_DPC_PIT1_MASK) ? "Type 1" : ""); printf("Data Protection Settings: "); ptype = (nsdata->dps >> NVME_NS_DATA_DPS_PIT_SHIFT) & @@ -238,7 +238,8 @@ identify(const struct cmd *f, int argc, char *argv[]) int fd; uint32_t nsid; - arg_parse(argc, argv, f); + if (arg_parse(argc, argv, f)) + return; open_dev(opt.dev, &fd, 1, 1); get_nsid(fd, &path, &nsid); Modified: stable/12/sbin/nvmecontrol/logpage.c ============================================================================== --- stable/12/sbin/nvmecontrol/logpage.c Thu Apr 9 16:24:57 2020 (r359750) +++ stable/12/sbin/nvmecontrol/logpage.c Thu Apr 9 18:17:07 2020 (r359751) @@ -570,11 +570,11 @@ print_log_sanitize_status(const struct nvme_controller printf("Unknown"); break; } - p = (ss->sstat & NVME_SS_PAGE_SSTAT_PASSES_SHIFT) >> + p = (ss->sstat >> NVME_SS_PAGE_SSTAT_PASSES_SHIFT) & NVME_SS_PAGE_SSTAT_PASSES_MASK; if (p > 0) printf(", %d passes", p); - if ((ss->sstat & NVME_SS_PAGE_SSTAT_GDE_SHIFT) >> + if ((ss->sstat >> NVME_SS_PAGE_SSTAT_GDE_SHIFT) & NVME_SS_PAGE_SSTAT_GDE_MASK) printf(", Global Data Erased"); printf("\n"); Modified: stable/12/sbin/nvmecontrol/modules/wdc/wdc.c ============================================================================== --- stable/12/sbin/nvmecontrol/modules/wdc/wdc.c Thu Apr 9 16:24:57 2020 (r359750) +++ stable/12/sbin/nvmecontrol/modules/wdc/wdc.c Thu Apr 9 18:17:07 2020 (r359751) @@ -275,7 +275,7 @@ print_hgst_info_subpage_gen(void *buf, uint16_t subtyp wsp++; /* Flags, just ignore */ plen = *wsp++; param = 0; - for (i = 0; i < plen; i++) + for (i = 0; i < plen && wsp < esp; i++) param |= (uint64_t)*wsp++ << (i * 8); printf(" %-30s: %jd\n", kv_lookup(kv, kv_count, ptype), (uintmax_t)param); } Modified: stable/12/sbin/nvmecontrol/nsid.c ============================================================================== --- stable/12/sbin/nvmecontrol/nsid.c Thu Apr 9 16:24:57 2020 (r359750) +++ stable/12/sbin/nvmecontrol/nsid.c Thu Apr 9 18:17:07 2020 (r359751) @@ -70,7 +70,8 @@ gnsid(const struct cmd *f, int argc, char *argv[]) int fd; uint32_t nsid; - arg_parse(argc, argv, f); + if (arg_parse(argc, argv, f)) + return; open_dev(nsid_opt.dev, &fd, 1, 1); get_nsid(fd, &path, &nsid); Modified: stable/12/sbin/nvmecontrol/passthru.c ============================================================================== --- stable/12/sbin/nvmecontrol/passthru.c Thu Apr 9 16:24:57 2020 (r359750) +++ stable/12/sbin/nvmecontrol/passthru.c Thu Apr 9 18:17:07 2020 (r359751) @@ -158,10 +158,12 @@ static void passthru(const struct cmd *f, int argc, char *argv[]) { int fd = -1, ifd = -1; + size_t bytes_read; void *data = NULL, *metadata = NULL; struct nvme_pt_command pt; - arg_parse(argc, argv, f); + if (arg_parse(argc, argv, f)) + return; open_dev(argv[optind], &fd, 1, 1); if (opt.read && opt.write) @@ -189,8 +191,12 @@ passthru(const struct cmd *f, int argc, char *argv[]) goto cleanup; } memset(data, opt.prefill, opt.data_len); - if (opt.write && read(ifd, data, opt.data_len) < 0) { - warn("read %s", *opt.ifn ? opt.ifn : "stdin"); + if (opt.write && + (bytes_read = read(ifd, data, opt.data_len)) != + opt.data_len) { + warn("read %s; expected %u bytes; got %zd", + *opt.ifn ? opt.ifn : "stdin", + opt.data_len, bytes_read); goto cleanup; } } @@ -249,6 +255,10 @@ passthru(const struct cmd *f, int argc, char *argv[]) } } cleanup: + free(data); + close(fd); + if (ifd > -1) + close(ifd); if (errno) exit(1); } Modified: stable/12/sbin/nvmecontrol/power.c ============================================================================== --- stable/12/sbin/nvmecontrol/power.c Thu Apr 9 16:24:57 2020 (r359750) +++ stable/12/sbin/nvmecontrol/power.c Thu Apr 9 18:17:07 2020 (r359751) @@ -145,7 +145,8 @@ power(const struct cmd *f, int argc, char *argv[]) struct nvme_controller_data cdata; int fd; - arg_parse(argc, argv, f); + if (arg_parse(argc, argv, f)) + return; if (opt.list && opt.power != POWER_NONE) { fprintf(stderr, "Can't set power and list power states\n"); Modified: stable/12/sbin/nvmecontrol/reset.c ============================================================================== --- stable/12/sbin/nvmecontrol/reset.c Thu Apr 9 16:24:57 2020 (r359750) +++ stable/12/sbin/nvmecontrol/reset.c Thu Apr 9 18:17:07 2020 (r359751) @@ -57,7 +57,8 @@ reset(const struct cmd *f, int argc, char *argv[]) { int fd; - arg_parse(argc, argv, f); + if (arg_parse(argc, argv, f)) + return; open_dev(opt.dev, &fd, 1, 1); if (ioctl(fd, NVME_RESET_CONTROLLER) < 0)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202004091817.039IH7sr080044>