Skip to content

Commit a8a3bc2

Browse files
ddissbrauner
authored andcommitted
initramfs: avoid memcpy for hex header fields
newc/crc cpio headers contain a bunch of 8-character hexadecimal fields which we convert via simple_strtoul(), following memcpy() into a zero-terminated stack buffer. The new simple_strntoul() helper allows us to pass in max_chars=8 to avoid zero-termination and memcpy(). Signed-off-by: David Disseldorp <ddiss@suse.de> Link: https://lore.kernel.org/r/20250304061020.9815-5-ddiss@suse.de Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent fcc1550 commit a8a3bc2

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

init/initramfs.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,11 @@ static __initdata u32 hdr_csum;
189189
static void __init parse_header(char *s)
190190
{
191191
unsigned long parsed[13];
192-
char buf[9];
193192
int i;
194193

195-
buf[8] = '\0';
196-
for (i = 0, s += 6; i < 13; i++, s += 8) {
197-
memcpy(buf, s, 8);
198-
parsed[i] = simple_strtoul(buf, NULL, 16);
199-
}
194+
for (i = 0, s += 6; i < 13; i++, s += 8)
195+
parsed[i] = simple_strntoul(s, NULL, 16, 8);
196+
200197
ino = parsed[0];
201198
mode = parsed[1];
202199
uid = parsed[2];

0 commit comments

Comments
 (0)