summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordzwdz2021-11-07 17:46:37 +0100
committerdzwdz2021-11-07 17:46:37 +0100
commit18470f2b4571d6779d1ee3f721d4b262349f373c (patch)
tree383915ba15b8c9bdd19168bca34c6d881607a740 /src
parente8f94805c9da44de35c6d4aedc253f1da6bd2bbd (diff)
init/tar: check length of found file
before this, you could open("/init/1") to open /init/1.txt
Diffstat (limited to 'src')
-rw-r--r--src/init/tar.c3
1 files changed, 2 insertions, 1 deletions
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);