git: 1d1298269d4c - main - loader.efi: Simplify the code for null decompression a little

From: Warner Losh <imp_at_FreeBSD.org>
Date: Fri, 10 Jul 2026 04:18:43 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=1d1298269d4c6e3ce41db6265f32ff6c2faecaf7

commit 1d1298269d4c6e3ce41db6265f32ff6c2faecaf7
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2026-07-10 04:04:40 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-07-10 04:09:41 +0000

    loader.efi: Simplify the code for null decompression a little
    
    This code is simpler when we spell it the Unix way. Also, add sanity
    checks to make sure the offset is where we think it is.
    
    Fixes: afee781523e4 ("loader.efi: Recognize new memdisk=<url> and memcd=<url> options")
    Sponsored by: Netflix
    Differential Revision:  https://reviews.freebsd.org/D58070
---
 stand/efi/loader/decompress.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/stand/efi/loader/decompress.c b/stand/efi/loader/decompress.c
index 1e18618db6f2..5c16f7d9bb2a 100644
--- a/stand/efi/loader/decompress.c
+++ b/stand/efi/loader/decompress.c
@@ -335,10 +335,14 @@ null_step(decomp_state *dctx, uint8_t *buf, size_t len, size_t offset)
 		printf("Too much data recieved!");
 		return (err);
 	}
+	if ((uintptr_t)dctx->buf_cur - (uintptr_t)dctx->buf != offset) {
+		printf("OH NO! The offset is %llu but I expected %llu\n", ULL(offset),
+		    ULL((uintptr_t)dctx->buf_cur - (uintptr_t)dctx->buf));
+		return (err);
+	}
 
-	CHAR8 *src = buf;
-	CHAR8 *dst = (void*)(uintptr_t)(dctx->buf + offset);
-	BS->CopyMem(dst, src, len);
+	memcpy(dctx->buf_cur, buf, len);
+	dctx->buf_cur += len;
 	return (end == dctx->size ? done : ok);
 }