diff options
author | dzwdz | 2022-05-01 19:25:22 +0200 |
---|---|---|
committer | dzwdz | 2022-05-01 19:25:22 +0200 |
commit | 7c62817193517f298bc566f3803c00d53a9a2b94 (patch) | |
tree | 8d6b95059e5f89be239e303ae53c847c88edea72 /src/init/tar.c | |
parent | 681e6b45b6f22f30d29745fa9a400558fe6dada5 (diff) |
init/fs: make directory listings respect offsets
Diffstat (limited to 'src/init/tar.c')
-rw-r--r-- | src/init/tar.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/init/tar.c b/src/init/tar.c index 1f1c42e..c289edc 100644 --- a/src/init/tar.c +++ b/src/init/tar.c @@ -79,6 +79,7 @@ static void tar_read(struct fs_wait_response *res, void *base, size_t base_len) case '5': /* directory */ meta_len = strlen(meta); + size_t to_skip = res->offset; /* find files in dir */ for (size_t off = 0; off < base_len;) { @@ -97,11 +98,19 @@ static void tar_read(struct fs_wait_response *res, void *base, size_t base_len) while (*next && *next != '/') next++; if (*next == '/') next++; if (*next == '\0') { - /* it doesn't - so let's add it to the result */ - memcpy(buf + buf_pos, suffix, suffix_len); - buf[buf_pos + suffix_len] = '\0'; - buf_pos += suffix_len + 1; - // TODO no buffer overrun check + if (to_skip > suffix_len) { + to_skip -= suffix_len; + } else { + suffix += to_skip; + suffix_len -= to_skip; + to_skip = 0; + + /* it doesn't - so let's add it to the result */ + memcpy(buf + buf_pos, suffix, suffix_len); + buf[buf_pos + suffix_len] = '\0'; + buf_pos += suffix_len + 1; + // TODO no buffer overrun check + } } } |