From 18470f2b4571d6779d1ee3f721d4b262349f373c Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sun, 7 Nov 2021 17:46:37 +0100 Subject: init/tar: check length of found file before this, you could open("/init/1") to open /init/1.txt --- src/init/tar.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/init/tar.c b/src/init/tar.c index 89f4e69..1a064d6 100644 --- a/src/init/tar.c +++ b/src/init/tar.c @@ -64,7 +64,8 @@ static void *tar_find(const char *path, size_t path_len, void *base, size_t base for (size_t off = 0; off < base_len;) { if (0 != memcmp(base + off + 257, "ustar", 5)) break; // not a metadata sector - if (0 == memcmp(base + off, path, path_len)) + if (0 == memcmp(base + off, path, path_len) && + *(char*)(base + off + path_len) == '\0') return base + off; // file found, quit size = tar_size(base + off); -- cgit v1.2.3