From 185e7fd6ee848c13bf7d0306d880cd67b6df4cac Mon Sep 17 00:00:00 2001 From: krw Date: Wed, 13 Apr 2022 22:29:30 +0000 Subject: [PATCH] Correct a gh_part_csum calculation used in debug output. Always calculate the GPT partition entries checksum over gh_part_num * gh_part_size bytes, not the maximal size of the internal partition entries array. No functional change. --- sbin/fdisk/gpt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c index 8e8d9834b13..9d06444bcc6 100644 --- a/sbin/fdisk/gpt.c +++ b/sbin/fdisk/gpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.c,v 1.63 2022/04/13 15:32:33 krw Exp $ */ +/* $OpenBSD: gpt.c,v 1.64 2022/04/13 22:29:30 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller * Copyright (c) 2015 Kenneth R Westerback @@ -433,7 +433,7 @@ add_partition(const uint8_t *beuuid, const char *name, uint64_t sectors) { struct uuid uuid, gp_type; int rslt; - uint64_t end, freesectors, start; + uint64_t end, freesectors, gpbytes, start; uint32_t status, pn, pncnt; uuid_dec_be(beuuid, &uuid); @@ -477,7 +477,8 @@ add_partition(const uint8_t *beuuid, const char *name, uint64_t sectors) goto done; uuid_enc_le(&gp[pn].gp_guid, &uuid); - gh.gh_part_csum = htole32(crc32((unsigned char *)&gp, sizeof(gp))); + gpbytes = letoh32(gh.gh_part_num) * letoh32(gh.gh_part_size); + gh.gh_part_csum = htole32(crc32((unsigned char *)&gp, gpbytes)); gh.gh_csum = 0; gh.gh_csum = htole32(crc32((unsigned char *)&gh, letoh32(gh.gh_size))); -- 2.20.1