Skip to content

Commit c6b8a81

Browse files
authored
ls,dir,vdir: protect names against argv[0] (#11371)
1 parent 6c3de3e commit c6b8a81

5 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/uu/dir/src/dir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
6262
// an uu_app function, so we return the `ls` app.
6363
pub fn uu_app() -> Command {
6464
uu_ls::uu_app()
65+
.name("dir")
6566
.override_usage(format_usage(&translate!("dir-usage")))
6667
.about(translate!("dir-about"))
6768
}

src/uu/ls/src/ls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
12651265

12661266
pub fn uu_app() -> Command {
12671267
uucore::clap_localization::configure_localized_command(
1268-
Command::new(uucore::util_name())
1268+
Command::new("ls")
12691269
.version(uucore::crate_version!())
12701270
.override_usage(format_usage(&translate!("ls-usage")))
12711271
.about(translate!("ls-about")),

src/uu/vdir/src/vdir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
6262
// an uu_app function, so we need this dummy one.
6363
pub fn uu_app() -> Command {
6464
uu_ls::uu_app()
65+
.name("vdir")
6566
.override_usage(format_usage(&translate!("vdir-usage")))
6667
.about(translate!("vdir-about"))
6768
}

tests/by-util/test_dir.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,12 @@ fn test_help_shows_dir_not_ls() {
7474
"Help should not show 'ls [OPTION]'"
7575
);
7676
}
77+
78+
#[test]
79+
fn test_version() {
80+
new_ucmd!()
81+
.arg("--version")
82+
.succeeds()
83+
.no_stderr()
84+
.stdout_is(format!("dir {}\n", uucore::crate_version!()));
85+
}

tests/by-util/test_vdir.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,12 @@ fn test_help_shows_vdir_not_ls() {
7474
"Help should not show 'ls [OPTION]'"
7575
);
7676
}
77+
78+
#[test]
79+
fn test_version() {
80+
new_ucmd!()
81+
.arg("--version")
82+
.succeeds()
83+
.no_stderr()
84+
.stdout_is(format!("vdir {}\n", uucore::crate_version!()));
85+
}

0 commit comments

Comments
 (0)