diff options
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 + } } } |