Skip to contentSkip to conversation

alpha: boot: check OSFLAGS length in start_kernel()

PATCH New Mohamed Salem Gorrab 1 participant 1 message Nov 19 Alpha port

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 alpha: boot: check OSFLAGS length in start_kernel()

bootp.c and bootpz.c reject a length >= sizeof(envval) from callback_getenv() before writing the terminating NUL. main.c only rejects negative values, so a return value of 256 would write one byte past the end of envval.

Use the same check as the other two files. I don't know whether the SRM firmware can actually return a length equal to the buffer size, so this is mainly for consistency. I have not tested on Alpha hardware.

---
 arch/alpha/boot/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/alpha/boot/main.c +1 -1
index 22a1cb0264afe6397ef2598c107f88280b979d63..0ce301edb219dc0c2fbabe5f692b48437a79d3b1 100644
@@ -176,7 +176,7 @@ void start_kernel(void)
 	}
 
 	nbytes = callback_getenv(ENV_BOOTED_OSFLAGS, envval, sizeof(envval));
-	if (nbytes < 0) {
+	if (nbytes < 0 || nbytes >= sizeof(envval)) {
 		nbytes = 0;
 	}
 	envval[nbytes] = '\0';

---
base-commit: 4405c18c95d2d0f99f6c581ef0ee8591a1aa6ccd
change-id: 20261119-alpha-osflags-d51e88f028b3

Best regards,

Signature · 1 line
Mohamed Salem Gorrab <[email protected]>