Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/uu/chroot/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ chroot-error-no-group-specified = no group specified for unknown uid: { $uid }
chroot-error-no-such-user = invalid user
chroot-error-no-such-group = invalid group
chroot-error-no-such-directory = cannot change root directory to { $dir }: no such directory
chroot-error-cannot-stat = cannot change root directory to { $dir }: { $err }
chroot-error-set-gid-failed = cannot set gid to { $gid }: { $err }
chroot-error-set-groups-failed = cannot set groups: { $err }
chroot-error-set-user-failed = cannot set user to { $user }: { $err }
1 change: 1 addition & 0 deletions src/uu/chroot/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ chroot-error-no-group-specified = aucun groupe spécifié pour l'uid inconnu : {
chroot-error-no-such-user = utilisateur invalide
chroot-error-no-such-group = groupe invalide
chroot-error-no-such-directory = impossible de changer le répertoire racine vers { $dir } : aucun répertoire de ce type
chroot-error-cannot-stat = impossible de changer le répertoire racine vers { $dir } : { $err }
chroot-error-set-gid-failed = impossible de définir le gid à { $gid } : { $err }
chroot-error-set-groups-failed = impossible de définir les groupes : { $err }
chroot-error-set-user-failed = impossible de définir l'utilisateur à { $user } : { $err }
8 changes: 8 additions & 0 deletions src/uu/chroot/src/chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@
options.chroot_target = resolved;
}

// Probe the path with `metadata` so the *original* I/O error reaches the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please make the comment shorter

// user. `Path::is_dir()` swallows that error and reports `false` for any
// failure — including `ENAMETOOLONG` (a 256-char path on Linux), which GNU

Check warning on line 199 in src/uu/chroot/src/chroot.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'ENAMETOOLONG' (file:'src/uu/chroot/src/chroot.rs', line:199)
// surfaces as "File name too long". Without this, a too-long NEWROOT
// would be misreported as "no such directory".
if let Err(e) = std::fs::metadata(&options.newroot) {
return Err(ChrootError::CannotStat(options.newroot, e).into());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should remove .is_dir() on many platforms instead of adding such hack to extract err from ctual chroot call instead.

if !options.newroot.is_dir() {
return Err(ChrootError::NoSuchDirectory(options.newroot).into());
}
Expand Down
4 changes: 4 additions & 0 deletions src/uu/chroot/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
#[error("{}", translate!("chroot-error-no-such-directory", "dir" => _0.quote()))]
NoSuchDirectory(PathBuf),

/// The given path could not be stat'd (e.g. ENAMETOOLONG, EACCES).

Check warning on line 59 in src/uu/chroot/src/error.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'ENAMETOOLONG' (file:'src/uu/chroot/src/error.rs', line:59)
#[error("{}", translate!("chroot-error-cannot-stat", "dir" => _0.quote(), "err" => _1))]
CannotStat(PathBuf, #[source] Error),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this needed even it is extracted from OS?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I opened a better alternative #13881 .

/// The call to `setgid()` failed.
#[error("{}", translate!("chroot-error-set-gid-failed", "gid" => _0, "err" => _1))]
SetGidFailed(String, #[source] Error),
Expand Down
16 changes: 16 additions & 0 deletions tests/by-util/test_chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@
.stderr_is("chroot: cannot change root directory to 'a': no such directory\n");
}

#[test]
#[cfg(not(target_os = "android"))]
fn test_filename_too_long() {
// Regression for #13156: a NEWROOT longer than NAME_MAX (255 bytes on
// Linux) used to be misreported as "no such directory" because
// `Path::is_dir()` swallows ENAMETOOLONG. GNU surfaces the real error.

Check warning on line 64 in tests/by-util/test_chroot.rs

View workflow job for this annotation

GitHub Actions / Style/spelling (ubuntu-latest, feat_os_unix)

WARNING: `cspell`: Unknown word 'ENAMETOOLONG' (file:'tests/by-util/test_chroot.rs', line:64)
let long_name = "A".repeat(256);
let expected = format!(
"chroot: cannot change root directory to '{long_name}': File name too long (os error 63)\n"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please use the strip_errno in the code to remove the (os error 63)

);
new_ucmd!()
.arg(&long_name)
.fails_with_code(125)
.stderr_is(expected);
}

#[test]
fn test_multiple_group_args() {
let ts = TestScenario::new(util_name!());
Expand Down
Loading