Skip to content

Commit 00b18ff

Browse files
authored
Merge branch 'main' into fix/ptx-tex-format-bug
2 parents 008b202 + 9064619 commit 00b18ff

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

.github/workflows/CICD.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,9 @@ jobs:
782782
# We also create a couple optional files pinky looks for
783783
touch /home/runner/.project
784784
echo "foo" > /home/runner/.plan
785+
# add user with digital username for testing with issue #7787
786+
echo 200:x:2000:2000::/home/200:/bin/bash | sudo tee -a /etc/passwd
787+
echo 200:x:2000: | sudo tee -a /etc/group
785788
;;
786789
esac
787790
- uses: taiki-e/install-action@v2
@@ -1156,6 +1159,9 @@ jobs:
11561159
# We also create a couple optional files pinky looks for
11571160
touch /home/runner/.project
11581161
echo "foo" > /home/runner/.plan
1162+
# add user with digital username for testing with issue #7787
1163+
echo 200:x:2000:2000::/home/200:/bin/bash | sudo tee -a /etc/passwd
1164+
echo 200:x:2000: | sudo tee -a /etc/group
11591165
;;
11601166
esac
11611167

src/uucore/src/lib/features/entries.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,17 @@ macro_rules! f {
309309
impl<'a> Locate<&'a str> for $st {
310310
fn locate(k: &'a str) -> IOResult<Self> {
311311
let _guard = PW_LOCK.lock();
312-
if let Ok(id) = k.parse::<$t>() {
313-
// SAFETY: We're holding PW_LOCK.
314-
unsafe {
312+
// SAFETY: We're holding PW_LOCK.
313+
unsafe {
314+
let cstring = CString::new(k)?;
315+
// try to get user or group with name matching the input with these tow lines:
316+
// f!(getpwnam, getpwuid, uid_t, Passwd);
317+
// f!(getgrnam, getgrgid, gid_t, Group);
318+
let data = $fnam(cstring.as_ptr());
319+
if !data.is_null() {
320+
return Ok($st::from_raw(ptr::read(data as *const _)));
321+
}
322+
if let Ok(id) = k.parse::<$t>() {
315323
let data = $fid(id);
316324
if !data.is_null() {
317325
Ok($st::from_raw(ptr::read(data as *const _)))
@@ -321,17 +329,8 @@ macro_rules! f {
321329
format!("No such id: {id}"),
322330
))
323331
}
324-
}
325-
} else {
326-
// SAFETY: We're holding PW_LOCK.
327-
unsafe {
328-
let cstring = CString::new(k).unwrap();
329-
let data = $fnam(cstring.as_ptr());
330-
if !data.is_null() {
331-
Ok($st::from_raw(ptr::read(data as *const _)))
332-
} else {
333-
Err(IOError::new(ErrorKind::NotFound, format!("Not found: {k}")))
334-
}
332+
} else {
333+
Err(IOError::new(ErrorKind::NotFound, format!("Not found: {k}")))
335334
}
336335
}
337336
}

tests/by-util/test_id.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
// spell-checker:ignore (ToDO) coreutil
77

8+
use std::process::{Command, Stdio};
89
use uutests::new_ucmd;
910
use uutests::unwrap_or_return;
1011
use uutests::util::{TestScenario, check_coreutil_version, expected_result, is_ci, whoami};
@@ -475,3 +476,27 @@ fn test_id_pretty_print_password_record() {
475476
.fails()
476477
.stderr_contains("the argument '-p' cannot be used with '-P'");
477478
}
479+
480+
/// This test requires user with username 200 on system
481+
#[test]
482+
#[cfg(unix)]
483+
fn test_id_digital_username() {
484+
match Command::new("id")
485+
.arg("200")
486+
.stdout(Stdio::null())
487+
.stderr(Stdio::null())
488+
.status()
489+
{
490+
Ok(ret) if ret.success() => {}
491+
Ok(_) => {
492+
println!("Test skipped; requires user with username 200 on system");
493+
return;
494+
}
495+
Err(e) => {
496+
println!("failed to run id command: {e}");
497+
return;
498+
}
499+
}
500+
501+
new_ucmd!().arg("200").succeeds();
502+
}

0 commit comments

Comments
 (0)