1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

pinky: fix off-by-one in GECOS parsing

This commit is contained in:
Justin Tracey 2022-02-18 00:03:11 -05:00
parent 37a0a74c19
commit 9430a9f355

View file

@ -239,6 +239,14 @@ fn time_string(ut: &Utmpx) -> String {
time::strftime("%b %e %H:%M", &ut.login_time()).unwrap() // LC_ALL=C
}
fn gecos_to_fullname(pw: &Passwd) -> String {
let mut gecos = pw.user_info.clone();
if let Some(n) = gecos.find(',') {
gecos.truncate(n);
}
gecos.replace('&', &pw.name.capitalize())
}
impl Pinky {
fn print_entry(&self, ut: &Utmpx) -> std::io::Result<()> {
let mut pts_path = PathBuf::from("/dev");
@ -265,11 +273,7 @@ impl Pinky {
if self.include_fullname {
if let Ok(pw) = Passwd::locate(ut.user().as_ref()) {
let mut gecos = pw.user_info;
if let Some(n) = gecos.find(',') {
gecos.truncate(n + 1);
}
print!(" {:<19.19}", gecos.replace('&', &pw.name.capitalize()));
print!(" {:<19.19}", gecos_to_fullname(&pw));
} else {
print!(" {:19}", " ???");
}
@ -331,7 +335,7 @@ impl Pinky {
for u in &self.names {
print!("Login name: {:<28}In real life: ", u);
if let Ok(pw) = Passwd::locate(u.as_str()) {
println!(" {}", pw.user_info.replace('&', &pw.name.capitalize()));
println!(" {}", gecos_to_fullname(&pw));
if self.include_home_and_shell {
print!("Directory: {:<29}", pw.user_dir);
println!("Shell: {}", pw.user_shell);