public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH mtd-utils] misc-utils: add missing error handling for 'bam' allocation in ftl_check.c
@ 2024-12-19 13:51 Anton Moryakov
  2024-12-20  1:11 ` Zhihao Cheng
  0 siblings, 1 reply; 2+ messages in thread
From: Anton Moryakov @ 2024-12-19 13:51 UTC (permalink / raw)
  To: chengzhihao1, linux-mtd; +Cc: Anton Moryakov

Corrections explained:
Added robust handling for malloc() failure by checking the returnvalueand providing a clear error message.

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>

---
 misc-utils/ftl_check.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/misc-utils/ftl_check.c b/misc-utils/ftl_check.c
index 5b2dae5..fe43a24 100644
--- a/misc-utils/ftl_check.c
+++ b/misc-utils/ftl_check.c
@@ -120,8 +120,17 @@ static void check_partition(int fd)
 
 	/* Create basic block allocation table for control blocks */
 	nbam = (mtd.erasesize >> hdr.BlockSize);
 	bam = malloc(nbam * sizeof(u_int));
+	if (!bam) {
+		perror("malloc failed");
+		return;
+	}

 	for (i = 0; i < le16_to_cpu(hdr.NumEraseUnits); i++) {
 		if (lseek(fd, (i << hdr.EraseUnitSize), SEEK_SET) == -1) {
 			perror("seek failed");
-- 
2.30.2


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-20  1:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-19 13:51 [PATCH mtd-utils] misc-utils: add missing error handling for 'bam' allocation in ftl_check.c Anton Moryakov
2024-12-20  1:11 ` Zhihao Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox