Skip to content

Commit 87b2ad7

Browse files
matorojsmolic
authored andcommitted
sys-fs/genext2fs: revbump 1.5.0-r1, apply sparc SIGBUS patch
Addresses https://bugs.gentoo.org/829270 by backporting my patch from bestouff/genext2fs#32 Bug: https://bugs.gentoo.org/828930 Closes: https://bugs.gentoo.org/829270 Signed-off-by: matoro <[email protected]> Closes: #26332 Signed-off-by: Jakov Smolić <[email protected]>
1 parent 9f84029 commit 87b2ad7

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
From 9651f5df1c95cdfee3d8f5f3f989fe326547f5d0 Mon Sep 17 00:00:00 2001
2+
From: matoro <[email protected]>
3+
Date: Mon, 16 May 2022 21:54:21 -0400
4+
Subject: [PATCH 1/2] Fix alignment issues for strict architectures
5+
6+
Fixes two locations where unaligned accesses will cause bus errors on
7+
architectures that are strict about such accesses, namely sparc.
8+
9+
The first is in swab32_into, which is called with an offset of +1 into
10+
an unsigned char array from mklink_fs.
11+
12+
The second is in add2fs_from_tarball when checking the validity of a
13+
tarball, which casts a string from an unaligned position inside a struct
14+
to a long.
15+
16+
After these changes, the test suite passes on sparc.
17+
---
18+
genext2fs.c | 15 +++++++++------
19+
1 file changed, 9 insertions(+), 6 deletions(-)
20+
21+
diff --git a/genext2fs.c b/genext2fs.c
22+
index 96bbb43..404f31e 100644
23+
--- a/genext2fs.c
24+
+++ b/genext2fs.c
25+
@@ -2058,11 +2058,14 @@ mkdir_fs(filesystem *fs, uint32 parent_nod, const char *name, uint32 mode,
26+
27+
// byte swapping for symlinks
28+
static inline void
29+
-swab32_into(uint32 *dst, uint32 *src, size_t n)
30+
+swab32_into(uint32 *dst, uint8 *src, size_t n)
31+
{
32+
size_t i;
33+
- for(i = 0; i < n; i++)
34+
- dst[i] = swab32(src[i]);
35+
+ for(i = 0; i < n; i++) {
36+
+ uint32 tmp_buf;
37+
+ memcpy(&tmp_buf, src + i * sizeof(uint32) / sizeof(uint8), sizeof(uint32) / sizeof(uint8));
38+
+ dst[i] = swab32(tmp_buf);
39+
+ }
40+
}
41+
42+
// make a symlink
43+
@@ -2079,7 +2082,7 @@ mklink_fs(filesystem *fs, uint32 parent_nod, const char *name, size_t size, uint
44+
45+
if (size < 4 * (EXT2_TIND_BLOCK + 1))
46+
if (fs->swapit)
47+
- swab32_into(node->i_block, (uint32 *)b, EXT2_TIND_BLOCK + 1);
48+
+ swab32_into(node->i_block, b, EXT2_TIND_BLOCK + 1);
49+
else
50+
memcpy(node->i_block, b, 4 * (EXT2_TIND_BLOCK + 1));
51+
else
52+
@@ -2290,7 +2293,7 @@ add2fs_from_tarball(filesystem *fs, uint32 this_nod, FILE * fh, int squash_uids,
53+
continue;
54+
} else
55+
nbnull = 0;
56+
- if (*(long *)tarhead->ustar != *(long *)"ustar\00000" && strcmp(tarhead->ustar, "ustar "))
57+
+ if (memcmp(tarhead->ustar, "ustar\00000", sizeof(long)) && strcmp(tarhead->ustar, "ustar "))
58+
error_msg_and_die("not a tarball");
59+
signed_checksum = unsigned_checksum = 0;
60+
checksum = OCTAL_READ(tarhead->checksum);
61+
@@ -3351,7 +3354,7 @@ print_link(filesystem *fs, uint32 nod)
62+
uint32 *buf = malloc(4 * (EXT2_TIND_BLOCK + 1));
63+
if (buf == NULL)
64+
error_msg_and_die(memory_exhausted);
65+
- swab32_into(buf, node->i_block, EXT2_TIND_BLOCK + 1);
66+
+ swab32_into(buf, (uint8*)node->i_block, EXT2_TIND_BLOCK + 1);
67+
printf("links to '%s'\n", (char*) buf);
68+
free(buf);
69+
} else {
70+
71+
From 4a99c22603fb01ca8d6c6c4cb9873f50124ac025 Mon Sep 17 00:00:00 2001
72+
From: matoro <[email protected]>
73+
Date: Wed, 18 May 2022 11:46:44 -0400
74+
Subject: [PATCH 2/2] Hardcode length of hardcoded char array instead of
75+
sizeof(long)
76+
77+
sizeof(long) != 8 on 32-bit.
78+
---
79+
genext2fs.c | 2 +-
80+
1 file changed, 1 insertion(+), 1 deletion(-)
81+
82+
diff --git a/genext2fs.c b/genext2fs.c
83+
index 404f31e..e8c71ff 100644
84+
--- a/genext2fs.c
85+
+++ b/genext2fs.c
86+
@@ -2293,7 +2293,7 @@ add2fs_from_tarball(filesystem *fs, uint32 this_nod, FILE * fh, int squash_uids,
87+
continue;
88+
} else
89+
nbnull = 0;
90+
- if (memcmp(tarhead->ustar, "ustar\00000", sizeof(long)) && strcmp(tarhead->ustar, "ustar "))
91+
+ if (memcmp(tarhead->ustar, "ustar\00000", 8) && strcmp(tarhead->ustar, "ustar "))
92+
error_msg_and_die("not a tarball");
93+
signed_checksum = unsigned_checksum = 0;
94+
checksum = OCTAL_READ(tarhead->checksum);
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 1999-2022 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
EAPI=8
5+
6+
inherit autotools
7+
8+
DESCRIPTION="generate ext2 file systems"
9+
HOMEPAGE="https://github.com/bestouff/genext2fs"
10+
SRC_URI="https://github.com/bestouff/genext2fs/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz"
11+
12+
LICENSE="GPL-2"
13+
SLOT="0"
14+
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~mips ~ppc ~ppc64 ~sparc ~x86"
15+
16+
PATCHES=( "${FILESDIR}/backport-pr-32.patch" )
17+
18+
src_prepare() {
19+
default
20+
eautoreconf
21+
}

0 commit comments

Comments
 (0)