gpt(8): Explicitly avoid out of range in searching MBR partitions
authorAaron LI <aly@aaronly.me>
Tue, 18 Jun 2019 16:30:40 +0000 (00:30 +0800)
committerAaron LI <aly@aaronly.me>
Tue, 18 Jun 2019 16:30:40 +0000 (00:30 +0800)
Avoid running off the end of an array in case thing we're looking for
isn't there.  This is probably impossible, but not obvious.

Obtained-from: NetBSD
Bug-report: #3015

sbin/gpt/show.c

index 56ee395..7aa22d0 100644 (file)
@@ -135,9 +135,14 @@ show(int fd __unused)
                                if (m->map_start == p->map_start + start)
                                        break;
                        }
-                       printf("%d%s", mbr->mbr_part[i].part_typ,
-                           mbr->mbr_part[i].part_flag == 0x80 ?
-                           " (active)" : "");
+                       if (i == 4) {
+                               /* wasn't there */
+                               printf("[partition not found?]");
+                       } else {
+                               printf("%d%s", mbr->mbr_part[i].part_typ,
+                                   mbr->mbr_part[i].part_flag == 0x80 ?
+                                   " (active)" : "");
+                       }
                        break;
                case MAP_TYPE_GPT_PART:
                        printf("GPT part ");