public inbox for dash@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] expand: fix SIGBUS due to unaligned access
@ 2026-01-16 20:55 Natanael Copa
  2026-02-19  4:10 ` tiagodepalves
  2026-03-14  9:23 ` Herbert Xu
  0 siblings, 2 replies; 3+ messages in thread
From: Natanael Copa @ 2026-01-16 20:55 UTC (permalink / raw)
  To: dash; +Cc: Natanael Copa

Replace direct uint64_t dereference with memcpy() to avoid
SIGBUS on armv7 when p is not 8-byte aligned.

Fixes crashes in dash during IFS splitting on strict-alignment
architectures.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
 src/expand.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

v2:
- Added a couple more instances of unaligned access.

diff --git a/src/expand.c b/src/expand.c
index 8c8bf0e..98b65ba 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -961,13 +961,14 @@ static size_t memtodest(const char *p, size_t len, int flags)
 	if (likely(!(flags & (expq >> 3 | expq >> 4 | expq >> 8) &
 		     (QUOTES_ESC | EXP_MBCHAR)))) {
 		while (len >= 8) {
-			uint64_t x = *(uint64_t *)(p + count);
+			uint64_t x;
+			memcpy(&x, p + count, sizeof(x));
 
 			if ((x | (x - 0x0101010101010101)) &
 			    0x8080808080808080)
 				break;
 
-			*(uint64_t *)(q + count) = x;
+			memcpy(q + count, &x, sizeof(x));
 
 			count += 8;
 			len -= 8;
@@ -1335,7 +1336,7 @@ ifsbreakup(char *string, int maxargs, struct arglist *arglist)
 						unsigned char b[8];
 					} x;
 
-					x.qw = *(uint64_t *)p;
+					memcpy(&x.qw, p, sizeof(x.qw));
 
 					if ((x.qw & 0x8080808080808080))
 						break;
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-03-14  9:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-16 20:55 [PATCH v2] expand: fix SIGBUS due to unaligned access Natanael Copa
2026-02-19  4:10 ` tiagodepalves
2026-03-14  9:23 ` Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox