]> www.infradead.org Git - mtd-utils.git/commitdiff
misc-utils: add missing error handling for 'bam' allocation in ftl_check.c
authorAnton Moryakov <ant.v.moryakov@gmail.com>
Thu, 19 Dec 2024 13:51:03 +0000 (16:51 +0300)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Fri, 20 Dec 2024 17:35:13 +0000 (18:35 +0100)
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>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
misc-utils/ftl_check.c

index 5b2dae57530dc4d585f67ed6ddab92a26a941e53..fe6a91a14be56bce2599034b1e3d2fab9094fc25 100644 (file)
@@ -121,6 +121,10 @@ 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) {