diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2023-06-20 11:52:09 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2023-06-20 11:52:09 +0000 |
commit | 1e8488019e458de98a00582e0970221a3379dc8f (patch) | |
tree | 4ff5f2dee0773f22b9b8cf58482d646d654525ce /sbin | |
parent | b2f9f51078d8b83096809a30b40b540009440792 (diff) |
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.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/fdisk/gpt.c | 7 |
1 files 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 <mmu@grummel.net> * Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org> @@ -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; } |