authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-11-20 00:23:57+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-11-20 00:23:57+01:00
logc25cb39d17021692f81764e29054c0a819c6c735
treeeb23c02b0285b34fc23575c0b0eb3e408dc29fb3
parenta5691ee363c025775f9f7f3a59cb31503068add2
parentb174942e6a7e15bf78edc3098fcbcdf1b2fbccd2
signature Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #7160 from semarie/openbsd-getdents

openbsd: getdents could return invalid entry with d_fileno==0

1 files changed, 13 insertions(+), 6 deletions(-)

lib/std/fs.zig+13-6
......@@ -352,7 +352,7 @@ pub const Dir = struct {
352352
353353 const name = @ptrCast([*]u8, &darwin_entry.d_name)[0..darwin_entry.d_namlen];
354354
355 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
355 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or (darwin_entry.d_ino == 0)) {
356356 continue :start_over;
357357 }
358358
......@@ -393,17 +393,24 @@ pub const Dir = struct {
393393 self.index = 0;
394394 self.end_index = @intCast(usize, rc);
395395 }
396 const freebsd_entry = @ptrCast(*align(1) os.dirent, &self.buf[self.index]);
397 const next_index = self.index + freebsd_entry.reclen();
396 const bsd_entry = @ptrCast(*align(1) os.dirent, &self.buf[self.index]);
397 const next_index = self.index + bsd_entry.reclen();
398398 self.index = next_index;
399399
400 const name = @ptrCast([*]u8, &freebsd_entry.d_name)[0..freebsd_entry.d_namlen];
400 const name = @ptrCast([*]u8, &bsd_entry.d_name)[0..bsd_entry.d_namlen];
401401
402 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
402 const skip_zero_fileno = switch (builtin.os.tag) {
403 // d_fileno=0 is used to mark invalid entries or deleted files.
404 .openbsd, .netbsd => true,
405 else => false,
406 };
407 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..") or
408 (skip_zero_fileno and bsd_entry.d_fileno == 0))
409 {
403410 continue :start_over;
404411 }
405412
406 const entry_kind = switch (freebsd_entry.d_type) {
413 const entry_kind = switch (bsd_entry.d_type) {
407414 os.DT_BLK => Entry.Kind.BlockDevice,
408415 os.DT_CHR => Entry.Kind.CharacterDevice,
409416 os.DT_DIR => Entry.Kind.Directory,