summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2025-05-03 06:23:10 +0100
committerLeah Rowe <leah@libreboot.org>2025-05-03 06:23:10 +0100
commit44a1cc9ef85626a0d45c7b838a3637ec9f316540 (patch)
treefbdc72e31f8bc5046b66ae74762dbdfd96aa78bf
parenta17875c34593cf966e61aacb9285f324723bb245 (diff)
util/nvmutil: use x, not ?, for random characters
A user reported that '?' causes an error on zsh. See: https://codeberg.org/libreboot/lbmk/issues/261 For example: ./mk inject libreboot-XXXXXX.tar.xz setmac ??:??:??:??:??:?? The user got: zsh: no matches found: ??:??:??:??:??:?? The mitigation here is to double-quote, e.g.: ./mk inject libreboot-XXXXXX.tar.xz setmac "??:??:??:??:??:??" However, a lot of people won't do that. Therefore, I will retain the current behaviour but support x/X for randomness. Now lbmk uses x by default, instead. I will now update the documentation, accordingly. Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--include/inject.sh2
-rw-r--r--util/nvmutil/nvmutil.c12
2 files changed, 10 insertions, 4 deletions
diff --git a/include/inject.sh b/include/inject.sh
index 26bcd02f..beaebf4d 100644
--- a/include/inject.sh
+++ b/include/inject.sh
@@ -328,7 +328,7 @@ inject()
eval "`setvars "" nukemode new_mac xchanged`"
archive="$1";
- new_mac="??:??:??:??:??:??"
+ new_mac="xx:xx:xx:xx:xx:xx"
[ $# -gt 1 ] && case "$2" in
nuke)
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 12aabe4d..05459bb7 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -40,7 +40,7 @@ size_t partsize, gbe[2];
uint8_t nvmPartChanged[2] = {0, 0}, do_read[2] = {1, 1};
int flags, rfd, fd, part;
-const char *strMac = NULL, *strRMac = "??:??:??:??:??:??", *filename = NULL;
+const char *strMac = NULL, *strRMac = "xx:xx:xx:xx:xx:xx", *filename = NULL;
typedef struct op {
char *str;
@@ -278,8 +278,11 @@ parseMacString(const char *strMac, uint16_t *mac)
err(errno = EINVAL, "Invalid character '%c'",
strMac[i + nib]);
+ /* If random, ensure that local/unicast bits are set */
if ((byte == 0) && (nib == 1))
- if (strMac[i + nib] == '?') /* ?=random */
+ if ((strMac[i + nib] == '?') ||
+ (strMac[i + nib] == 'x') ||
+ (strMac[i + nib] == 'X')) /* random */
h = (h & 0xE) | 2; /* local, unicast */
mac[byte >> 1] |= ((uint16_t ) h)
@@ -302,7 +305,10 @@ hextonum(char ch)
return ch - 'A' + 10;
else if ((ch >= 'a') && (ch <= 'f'))
return ch - 'a' + 10;
- return (ch == '?') ? rhex() : 16;
+ else if ((ch == '?') || (ch == 'x') || (ch == 'X'))
+ return rhex(); /* random hex value */
+ else
+ return 16; /* error: invalid character */
}
uint8_t