diff --git a/init/initramfs.c b/init/initramfs.c index 3315849034c2d392b3a1e73d04e4c7d0487f9638..9c7fa4f0e07af3c01f8b1cd4ee38ac9f8cfb757d 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -457,6 +457,15 @@ static int __init do_name(void) { state = SkipIt; next_state = Reset; + + /* name_len > 0 && name_len <= PATH_MAX checked in do_header */ + if (collected[name_len - 1] != '\0') { + pr_err("initramfs name without nulterm: %.*s\n", + (int)name_len, collected); + error("malformed archive"); + return 1; + } + if (strcmp(collected, "TRAILER!!!") == 0) { free_hash(); return 0; @@ -571,6 +580,12 @@ static int __init do_copy(void) static int __init do_symlink(void) { + if (collected[name_len - 1] != '\0') { + pr_err("initramfs symlink without nulterm: %.*s\n", + (int)name_len, collected); + error("malformed archive"); + return 1; + } collected[N_ALIGN(name_len) + body_len] = '\0'; #ifdef CONFIG_IMA_DIGEST_LIST memcpy(previous_name_buf, collected, strlen(collected) + 1);