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

libstd: improve os::args() doc #18944

Merged
merged 1 commit into from
Nov 20, 2014
Merged

Conversation

liigo
Copy link
Contributor

@liigo liigo commented Nov 14, 2014

No description provided.

@huonw
Copy link
Member

huonw commented Nov 14, 2014

I don't think we have this as a guarantee, unfortunately; see, for example, http://stackoverflow.com/a/2051031/1256624. As an example:

// otherargv.rs

extern crate libc;
use std::ptr;

fn main() {
    let args = std::os::args();
    println!("{}", args);

    match args.len() {
        1 => unsafe {
            // call itself with a custom argv.
            libc::execv("./otherargv\0".as_ptr() as *const i8,
                        ["abc\0".as_ptr() as *const i8,
                         "def\0".as_ptr() as *const i8,
                         ptr::null()].as_mut_ptr());

        },
        2 => unsafe {
            // call itself with an empty argv.
            libc::execv("./otherargv\0".as_ptr() as *const i8,
                        [ptr::null()].as_mut_ptr());
        },
        _ => {}
    }
}

Running ./otherargv gives:

[./otherargv]
[abc, def]
[]

I think this is still a useful addition, but maybe it could be adjusted to something like:

The first element is traditionally the path to the executable, but it can be set to arbitrary text, and it may not even exist, so this property should not be relied upon for security purposes.

@liigo liigo force-pushed the improve-os-args-doc branch from 9b3a469 to 8347450 Compare November 15, 2014 02:03
@liigo
Copy link
Contributor Author

liigo commented Nov 15, 2014

@huonw Thank you! I updated and rebased. r?

@liigo
Copy link
Contributor Author

liigo commented Nov 19, 2014

ping @huonw

@bors bors merged commit 8347450 into rust-lang:master Nov 20, 2014
lnicola added a commit to lnicola/rust that referenced this pull request Jan 20, 2025
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.

3 participants