From 44612db3764ebbe43979d727a50358a6705b5675 Mon Sep 17 00:00:00 2001 From: krw Date: Tue, 20 Jun 2023 11:52:08 +0000 Subject: [PATCH] Take more care to ensure name_to_string() always returns a proper string. Don't rely on GPT partition name containing a terminating zero or the reserved bytes beyond gp_name being properly initialized to zero. --- sbin/fdisk/gpt.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c index 65e7e8eeb66..8e8badfe0b9 100644 --- a/sbin/fdisk/gpt.c +++ b/sbin/fdisk/gpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.c,v 1.92 2023/06/19 23:11:19 krw Exp $ */ +/* $OpenBSD: gpt.c,v 1.93 2023/06/20 11:52:08 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller * Copyright (c) 2015 Kenneth R Westerback @@ -77,10 +77,9 @@ name_to_string(const unsigned int pn) static char name[GPTPARTNAMESIZE + 1]; unsigned int i; - memset(name, 0, sizeof(name)); - - for (i = 0; i < sizeof(name) && gp[pn].gp_name[i] != 0; i++) + for (i = 0; i < GPTPARTNAMESIZE && gp[pn].gp_name[i] != 0; i++) name[i] = letoh16(gp[pn].gp_name[i]) & 0x7F; + name[i] = '\0'; return name; } -- 2.20.1