* [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
* Re: [PATCH mtd-utils] misc-utils: add missing error handling for 'bam' allocation in ftl_check.c
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
0 siblings, 0 replies; 2+ messages in thread
From: Zhihao Cheng @ 2024-12-20 1:11 UTC (permalink / raw)
To: Anton Moryakov, linux-mtd
在 2024/12/19 21:51, 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(+)
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
>
> 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");
>
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [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