Skip to content

Use an absolute path in test_process_output_fail_to_start #11784

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

Merged
merged 1 commit into from
Jan 31, 2014

Conversation

eminence
Copy link
Contributor

This test is designed to ensure that running a non-existent executable
results in a correct error message (FileNotFound in this case of this
test). However, if you try to run an executable that doesn't exist, and
that requires searching through the $PATH, and one of the $PATH components
is not readable, then a PermissionDenied error will be returned, instead
of FileNotFound.

Using an absolute path skips the $PATH search logic in exec, thus by-passing the logic in exec that would have returned a PermissionDenied

In the specific case of my machine, /usr/bin/games was part of $PATH, but my user account wasn't in the games group (thus being unable to read /usr/bin/games)

See the man pages for execv and execve for more details.

I've tested this on Linux and OSX, and I am fairly certain that there will be no problems on Windows

This test is designed to ensure that running a non-existent executable
results in a correct error message (FileNotFound in this case of this
test).  However, if you try to run an executable that doesn't exist, and
that requires searching through the $PATH, and one of the $PATH components
is not readable, then a PermissionDenied error will be returned, instead
of FileNotFound.
@@ -360,7 +360,7 @@ mod tests {
trapped_io_error = true;
assert_eq!(e.kind, FileNotFound);
}).inside(|| -> Option<run::ProcessOutput> {
run::process_output("no-binary-by-this-name-should-exist", [])
run::process_output("/no-binary-by-this-name-should-exist", [])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't paths in a different format on windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I don't think that matters in this case. Recall that we don't actually want to run this thing, only to confirm it doesn't exist. I don't have easy access to a Windows machine with Rust, but I do have access to a Windows machine.

The following code snippet gives CreateProcess an absolute path (with a forward slash), and CreateProcess is correctly returning ERROR_FILE_NOT_FOUND. So I believe this will work just fine for this rust test

#include <Windows.h>
#include <stdio.h>

int main() {

    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

    if( !CreateProcess( NULL,           // No module name (use command line)
                "/does_not_exist",      // Command line
                NULL,                   // Process handle not inheritable
                NULL,                   // Thread handle not inheritable
                FALSE,                  // Set handle inheritance to FALSE
                0,                      // No creation flags
                NULL,                   // Use parent's environment block
                NULL,                   // Use parent's starting directory
                &si,                    // Pointer to STARTUPINFO structure
                &pi )                   // Pointer to PROCESS_INFORMATION structure
      )
    {
        const DWORD err = GetLastError();
        if (err == ERROR_FILE_NOT_FOUND) {
            printf("FileNotFound\n");
        } else {
            printf( "CreateProcess failed (%d).\n", err );
        }
    }
    return;

}
d:\temp\> test.exe
FileNotFound

Also note that if I give a path to something that does exist, but also using unix-style forward slashes, CreateProcess will run the thing. I am not sure, however, where this behavior is documented.

bors added a commit that referenced this pull request Jan 31, 2014
This test is designed to ensure that running a non-existent executable
results in a correct error message (FileNotFound in this case of this
test).  However, if you try to run an executable that doesn't exist, and
that requires searching through the $PATH, and one of the $PATH components
is not readable, then a PermissionDenied error will be returned, instead
of FileNotFound.

Using an absolute path skips the $PATH search logic in exec, thus by-passing the logic in exec that would have returned a PermissionDenied

In the specific case of my machine, /usr/bin/games was part of $PATH, but my user account wasn't in the games group (thus being unable to read /usr/bin/games)

See the man pages for execv and execve for more details.

I've tested this on Linux and OSX, and I am fairly certain that there will be no problems on Windows
@eminence
Copy link
Contributor Author

I finally got around to testing this on Windows, and this test passes there too

@bors bors merged commit 506c71c into rust-lang:master Jan 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants