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

std.os.windows.GetFinalPathNameByHandle has a reachable unreachable #18756

Open
paperdave opened this issue Jan 30, 2024 · 5 comments
Open

std.os.windows.GetFinalPathNameByHandle has a reachable unreachable #18756

paperdave opened this issue Jan 30, 2024 · 5 comments
Labels
bug Observed behavior contradicts documented or intended behavior os-windows standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@paperdave
Copy link

Zig Version

0.12.0-dev.1828+225fe6ddb

Steps to Reproduce and Observed Behavior

this happened once when running bun-debug install

image

it seems this may be possible that the given input handle was already closed when it was attempted to get it's path read.

Since unreachable does not print any information about the state, I cannot report what the path returned from the windows API actually was. I also cannot reproduce this anymore.

Expected Behavior

GetFinalPathNameByHandle returning an error union, should return an error. And if it was to hit unreachable, it should be obvious what the mistake is.

@paperdave paperdave added the bug Observed behavior contradicts documented or intended behavior label Jan 30, 2024
@paperdave
Copy link
Author

image

it is also heavily implied this should work on an invalid file descriptor by the first part of this handling the invalid handle error

@dylan-conway
Copy link
Sponsor

Also reproed this a couple times in the last few minutes. final_path was \Device\MountPointManager. Without the expected_prefix, mem.indexOfPos will fail to find the path separator with this path.

@paperdave
Copy link
Author

this is a file descriptor use-after-free on our side (i have a custom format function for our FD type, which in debug mode prints the path)

but the case still applies to zig if you query the path of the mount point manager

const std = @import("std");
pub fn main() !void {
    const mgmt_path_u16 = std.unicode.utf8ToUtf16LeStringLiteral("\\??\\MountPointManager");
    const mgmt_handle = try std.os.windows.OpenFile(mgmt_path_u16, .{
        .access_mask = std.os.windows.SYNCHRONIZE,
        .share_access = std.os.windows.FILE_SHARE_READ | std.os.windows.FILE_SHARE_WRITE,
        .creation = std.os.windows.FILE_OPEN,
        .io_mode = .blocking,
    });

    var out: [64000]u16 = undefined;
    _ = try std.os.windows.GetFinalPathNameByHandle(mgmt_handle, .{ .volume_name = .Dos }, &out);
}

@zackradisic
Copy link

I also experienced this with this path: \Device\ConDrv

@andrewrk andrewrk added standard library This issue involves writing Zig code for the standard library. os-windows labels Mar 30, 2024
@andrewrk andrewrk added this to the 0.13.0 milestone Mar 30, 2024
@Jarred-Sumner
Copy link
Contributor

This also happens with \Device\Null

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 os-windows standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

5 participants