git: baa78c87eb07 - main - nvmecontrol: Minor correctness issues
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 12 Sep 2026 18:19:09 UTC
The branch main has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=baa78c87eb074fa8d9ee5625a6440d35f617e67f
commit baa78c87eb074fa8d9ee5625a6440d35f617e67f
Author: Warner Losh <imp@FreeBSD.org>
AuthorDate: 2026-09-11 14:54:17 +0000
Commit: Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-09-12 16:59:16 +0000
nvmecontrol: Minor correctness issues
Turn an assert into a bounds check to not overflow if the nvme drive
reports too many power states (we validate the user input, but not the
drive's identify data).
Use a uint32_t instead of int for entry so right shift we do is defined.
No functional changes.
Fixes: 35793364d722
Noticed by: claude + Sonet 5
Sponsored by: Netflix
---
sbin/nvmecontrol/power.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/sbin/nvmecontrol/power.c b/sbin/nvmecontrol/power.c
index 1ba28deb6c16..05187cd8dc51 100644
--- a/sbin/nvmecontrol/power.c
+++ b/sbin/nvmecontrol/power.c
@@ -28,7 +28,6 @@
#include <sys/param.h>
#include <sys/ioccom.h>
-#include <assert.h>
#include <ctype.h>
#include <err.h>
#include <fcntl.h>
@@ -158,7 +157,8 @@ power_apst_data_generate(struct nvme_controller_data *cdata,
{
int i, itpt, latency;
- assert(cdata->npss < num);
+ if (cdata->npss >= num)
+ errx(EX_UNAVAILABLE, "controller reports too many power states");
for (i = cdata->npss; i > 0; --i) {
if (!NVMEV(NVME_PWR_ST_NOPS,
@@ -207,7 +207,8 @@ power_apst_data_parse(struct nvme_controller_data *cdata,
static void
power_apst_show(uint64_t *data, int num, bool enabled)
{
- int entry, i;
+ uint32_t entry;
+ int i;
while (num > 0 && data[num - 1] == 0)
--num;