Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'readLink' fails on non-symlink file #9872

Closed
Daimanta opened this issue Sep 30, 2021 · 0 comments · Fixed by #9877
Closed

'readLink' fails on non-symlink file #9872

Daimanta opened this issue Sep 30, 2021 · 0 comments · Fixed by #9877
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@Daimanta
Copy link

Summary

When running the std.os.readLink function on a non-link path on Linux, an unreachable place of code is reached.

Setup

  1. WSL or Linux environment
  2. Zig 0.8.1

Reproduction

  1. Choose a non-link file in linux.
var buffer: [2 << 20]u8 = undefined;
const result = try std.fs.cwd().readLink(link, buffer[0..]);

result:

/home/foobar/zig/lib/std/os.zig:2559:19: 0x20a017 in std.os.readlinkatZ (readlink)
        EINVAL => unreachable,    

Analysis

The system call likely returns EINVAL if a non-link file is link resolved. The code at readlinkatZ doesn't expect this value as the switch case in unreachable.

Possible solution

Add a 'NotALink' error and return it when receiving EINVAL from the system.

@andrewrk andrewrk added standard library This issue involves writing Zig code for the standard library. bug Observed behavior contradicts documented or intended behavior labels Nov 20, 2021
@andrewrk andrewrk added this to the 0.9.0 milestone Nov 20, 2021
andrewrk pushed a commit that referenced this issue Nov 20, 2021
Closes #9872

Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants