mirror of
https://github.com/ziglang/zig.git
synced 2024-12-04 02:48:50 +00:00
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:
parent
399c428cb0
commit
9c53564af1
@ -2183,7 +2183,7 @@ pub const Walker = struct {
|
|||||||
while (true) {
|
while (true) {
|
||||||
if (self.stack.items.len == 0) return null;
|
if (self.stack.items.len == 0) return null;
|
||||||
// `top` becomes invalid after appending to `self.stack`.
|
// `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;
|
const dirname_len = top.dirname_len;
|
||||||
if (try top.dir_it.next()) |base| {
|
if (try top.dir_it.next()) |base| {
|
||||||
self.name_buffer.shrink(dirname_len);
|
self.name_buffer.shrink(dirname_len);
|
||||||
@ -2200,6 +2200,7 @@ pub const Walker = struct {
|
|||||||
.dir_it = new_dir.iterate(),
|
.dir_it = new_dir.iterate(),
|
||||||
.dirname_len = self.name_buffer.items.len,
|
.dirname_len = self.name_buffer.items.len,
|
||||||
});
|
});
|
||||||
|
top = &self.stack.items[self.stack.items.len - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Entry{
|
return Entry{
|
||||||
|
Loading…
Reference in New Issue
Block a user