fs: fix segfault in Walker.next

`top` might point to invalid memory after a call to self.stack.append
which causes a segfault.

Prevent this by recomputing `top`.

Fixes #7560
This commit is contained in:
Vincent Rischmann 2020-12-28 17:53:52 +01:00
parent 399c428cb0
commit 9c53564af1

View File

@ -2183,7 +2183,7 @@ pub const Walker = struct {
while (true) {
if (self.stack.items.len == 0) return null;
// `top` becomes invalid after appending to `self.stack`.
const top = &self.stack.items[self.stack.items.len - 1];
var top = &self.stack.items[self.stack.items.len - 1];
const dirname_len = top.dirname_len;
if (try top.dir_it.next()) |base| {
self.name_buffer.shrink(dirname_len);
@ -2200,6 +2200,7 @@ pub const Walker = struct {
.dir_it = new_dir.iterate(),
.dirname_len = self.name_buffer.items.len,
});
top = &self.stack.items[self.stack.items.len - 1];
}
}
return Entry{