Skip to contentSkip to conversation

libndctl: fix a potential buffer overflow

PATCH New Vishal Verma 1 participant 2 messages Oct 1, 2020 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Vishal Verma

author maintainer
#0 lore raw

PATCH 1/2 libndctl: fix a potential buffer overflow

Static analysis points out that the 'buf' in ndctl_dimm_is_active was inappropriately sized. We already have 'SYSFS_ATTR_SIZE' for such buffers, and it looks like this was just an oversight.

Fixes 0a4509d7de2f ("ndctl: enumerate interleave sets")
Cc Dan Williams <[email protected]>
---
 ndctl/lib/libndctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ndctl/lib/libndctl.c +1 -1
index 6556b33..5546963 100644
@@ -3675,8 +3675,8 @@ NDCTL_EXPORT int ndctl_dimm_is_active(struct ndctl_dimm *dimm)
 {
 	struct ndctl_ctx *ctx = ndctl_dimm_get_ctx(dimm);
 	char *path = dimm->dimm_buf;
+	char buf[SYSFS_ATTR_SIZE];
 	int len = dimm->buf_len;
-	char buf[20];
 
 	if (snprintf(path, len, "%s/state", dimm->dimm_path) >= len) {
 		err(ctx, "%s: buffer too small!\n",
Signature · 4 lines
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]
author maintainer
#1 lore raw

PATCH 2/2 ndctl/inject-error: remove logically dead code

Static analysis reports that the bb != NULL check is redundant because ndctl_namespace_bb_foreach already uses that as a loop condition. Remove it.

---
 ndctl/inject-error.c | 3 ---
 1 file changed, 3 deletions(-)
ndctl/inject-error.c +0 -3
index fe599ef..f6be6a5 100644
@@ -255,9 +255,6 @@ static int injection_status(struct ndctl_namespace *ndns)
 	}
 
 	ndctl_namespace_bb_foreach(ndns, bb) {
-		if (!bb)
-			break;
-
 		block = ndctl_bb_get_block(bb);
 		count = ndctl_bb_get_count(bb);
 		jbb = util_badblock_rec_to_json(block, count, ictx.json_flags);
Signature · 4 lines
2.26.2
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]