From: Anton Moryakov <ant.v.moryakov@gmail.com>
To: chengzhihao1@huawei.com, linux-mtd@lists.infradead.org
Cc: Anton Moryakov <ant.v.moryakov@gmail.com>
Subject: [PATCH mtd-utils] misc-utils: add missing error handling for 'bam' allocation in ftl_check.c
Date: Thu, 19 Dec 2024 16:51:03 +0300 [thread overview]
Message-ID: <20241219135103.712032-1-ant.v.moryakov@gmail.com> (raw)
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/
next reply other threads:[~2024-12-19 13:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-19 13:51 Anton Moryakov [this message]
2024-12-20 1:11 ` [PATCH mtd-utils] misc-utils: add missing error handling for 'bam' allocation in ftl_check.c Zhihao Cheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241219135103.712032-1-ant.v.moryakov@gmail.com \
--to=ant.v.moryakov@gmail.com \
--cc=chengzhihao1@huawei.com \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox