[PATCH] builtin: Fix unaligned access in conv_escape

Herbert Xu <[email protected]> Sun, 31 May 2026 13:51:02 +0800
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
When writing out the unicode character in conv_escape, use memcpy
instead of direct assignment as the output buffer may not be aligned
sufficiently.

Reported-by: Nathan Mills <[email protected]>
Fixes: 776424a8f915 ("parser: Add dollar single quote")
Signed-off-by: Herbert Xu <[email protected]>

diff --git a/src/bltin/printf.c b/src/bltin/printf.c
index 106aecd..c2c3615 100644
--- a/src/bltin/printf.c
+++ b/src/bltin/printf.c
@@ -419,7 +429,7 @@ hex:
 			USTPUTC(CTLMBCHAR, out);
 			USTPUTC(len, out);
 			STADJUST(mboff, out);
-			*(uint32_t *)out = value;
+			memcpy(out, &value, 4);
 			STADJUST(len, out);
 			USTPUTC(len, out);
 			USTPUTC(CTLMBCHAR, out);
-- 
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt