From: krw Date: Tue, 15 Mar 2022 17:59:39 +0000 (+0000) Subject: Always use letoh32(gh.gh_part_num) instead of NGPTPARTITIONS when X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5550db089975d452a18a086d28be58cc2d27aa7d;p=openbsd Always use letoh32(gh.gh_part_num) instead of NGPTPARTITIONS when scanning the GPT partition table. gh.gh_part_num reflects the actual size of the table read from/written to the disk and scanning possible entries between this value and the maximum allowed size of a partition table is pointless. No intentional functional change. --- diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index e6cc8712eff..673c7d08828 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.152 2022/02/04 18:21:33 krw Exp $ */ +/* $OpenBSD: cmd.c,v 1.153 2022/03/15 17:59:39 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -500,7 +500,7 @@ Xflag(char *args, struct mbr *mbr) printf("Partition %d flag value set to 0x%llx.\n", pn, val); } else { if (letoh64(gh.gh_sig) == GPTSIGNATURE) { - for (i = 0; i < NGPTPARTITIONS; i++) { + for (i = 0; i < letoh32(gh.gh_part_num); i++) { if (i == pn) gp[i].gp_attrs = htole64(GPTDOSACTIVE); else diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c index 61f2d6fd1ca..dac474b8544 100644 --- a/sbin/fdisk/gpt.c +++ b/sbin/fdisk/gpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.c,v 1.59 2022/03/11 22:29:55 krw Exp $ */ +/* $OpenBSD: gpt.c,v 1.60 2022/03/15 17:59:39 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller * Copyright (c) 2015 Kenneth R Westerback @@ -554,7 +554,7 @@ init_gp(const int how) if (how == GHANDGP) memset(&gp, 0, sizeof(gp)); else { - for (pn = 0; pn < NGPTPARTITIONS; pn++) { + for (pn = 0; pn < letoh32(gh.gh_part_num); pn++) { if (PRT_protected_guid(&gp[pn].gp_type)) continue; memset(&gp[pn], 0, sizeof(gp[pn])); diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c index 65bad6b40e6..d21b4e48f08 100644 --- a/sbin/fdisk/part.c +++ b/sbin/fdisk/part.c @@ -1,4 +1,4 @@ -/* $OpenBSD: part.c,v 1.120 2022/03/14 17:11:44 krw Exp $ */ +/* $OpenBSD: part.c,v 1.121 2022/03/15 17:59:39 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -208,7 +208,7 @@ PRT_protected_guid(const struct uuid *uuid) if (strncmp(str, efistr, UUID_STR_LEN) == 0) { /* Look for partitions indicating a need to preserve EFI Sys */ - for (i = 0; i < NGPTPARTITIONS; i++) { + for (i = 0; i < letoh32(gh.gh_part_num); i++) { typename = PRT_uuid_to_typename(&gp[i].gp_type); if (strncmp(typename, "APFS ", 5)) continue;