]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: assert if self_pte() returns NULL
authorSami Kerola <kerolasa@iki.fi>
Wed, 22 May 2019 18:45:54 +0000 (19:45 +0100)
committerSami Kerola <kerolasa@iki.fi>
Wed, 22 May 2019 18:45:54 +0000 (19:45 +0100)
The self_pte() can return NULL if partitions array is not large enough,
but that should also be impossible and definitely a bug.

libfdisk/src/dos.c:984:8: warning: potential null pointer dereference [-Wnull-dereference]
libfdisk/src/dos.c:1031:8: warning: potential null pointer dereference [-Wnull-dereference]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
libfdisk/src/dos.c

index 40b9aa758ca159bd6a4a1da44e08e84032439cdc..6dc276e8a64dbe6bd728f70efe629508c93c5fd9 100644 (file)
@@ -978,6 +978,8 @@ static int find_last_free_sector_in_range(
                last_moved = 0;
                for ( ; i < cxt->label->nparts_max; i++) {
                        struct pte *pe = self_pte(cxt, i);
+
+                       assert(pe);
                        fdisk_sector_t p_start = get_abs_partition_start(pe);
                        fdisk_sector_t p_end = get_abs_partition_end(pe);
 
@@ -1025,6 +1027,8 @@ static int find_first_free_sector_in_range(
                first_moved = 0;
                for (; i < cxt->label->nparts_max; i++) {
                        struct pte *pe = self_pte(cxt, i);
+
+                       assert(pe);
                        fdisk_sector_t p_start = get_abs_partition_start(pe);
                        fdisk_sector_t p_end = get_abs_partition_end(pe);