diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-03 23:37:59 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-03 23:37:59 +0000 |
| commit | 76d6900d696e9ea73f0473fb8298f313422b184f (patch) | |
| tree | 3dd3d262fe91c26d153418723ac4b650567bbb26 /util/nvmutil | |
| parent | 8c5c4e1b930d07e87e23894e9d50f3d1c00a70b7 (diff) | |
util/nvmutil: less obscure mac address zero check
make it totally clear what's going on.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'util/nvmutil')
| -rw-r--r-- | util/nvmutil/nvmutil.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c index 62821278..349bcd8c 100644 --- a/util/nvmutil/nvmutil.c +++ b/util/nvmutil/nvmutil.c @@ -23,7 +23,7 @@ static void read_gbe(void); static void read_gbe_part(int, int); static void cmd_setmac(void); static void parse_mac_string(void); -static void set_mac_byte(int, uint64_t *); +static void set_mac_byte(int); static void check_mac_separator(int); static void set_mac_nib(int, int, uint8_t *); static uint8_t hextonum(char); @@ -293,8 +293,9 @@ cmd_setmac(void) static void parse_mac_string(void) { + size_t c; int mac_pos; - uint64_t total = 0; + uint64_t mac_total; if (strnlen(mac, 20) != 17) err(EINVAL, "Invalid MAC address string length"); @@ -302,22 +303,26 @@ parse_mac_string(void) (void) memset(macbuf, 0, sizeof(macbuf)); for (mac_pos = 0; mac_pos < 16; mac_pos += 3) - set_mac_byte(mac_pos, &total); + set_mac_byte(mac_pos); - if (total == 0) + mac_total = 0; + for (c = 0; c < sizeof(macbuf); c++) + mac_total += macbuf[c]; + + if (mac_total == 0) err(EINVAL, "Invalid MAC (all-zero MAC address)"); if (macbuf[0] & 1) err(EINVAL, "Invalid MAC (multicast bit set)"); } static void -set_mac_byte(int mac_pos, uint64_t *total) +set_mac_byte(int mac_pos) { int nib; uint8_t h = 0; check_mac_separator(mac_pos); - for (nib = 0; nib < 2; nib++, *total += h) + for (nib = 0; nib < 2; nib++) set_mac_nib(mac_pos, nib, &h); } |
