From 702709a916dba072c514169f47a98342342228d6 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Thu, 31 Aug 2023 10:46:01 +0200 Subject: [PATCH] libpod: do not parse --hostuser in base 8 fix the parsing of --hostuser to treat the input in base 10. Closes: https://github.com/containers/podman/issues/19800 Signed-off-by: Giuseppe Scrivano --- libpod/container_internal_common.go | 4 ++-- test/system/030-run.bats | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go index f7a51f5a32..a8747f8490 100644 --- a/libpod/container_internal_common.go +++ b/libpod/container_internal_common.go @@ -821,12 +821,12 @@ func lookupHostUser(name string) (*runcuser.ExecUser, error) { if err != nil { return &execUser, err } - uid, err := strconv.ParseUint(u.Uid, 8, 32) + uid, err := strconv.ParseUint(u.Uid, 10, 32) if err != nil { return &execUser, err } - gid, err := strconv.ParseUint(u.Gid, 8, 32) + gid, err := strconv.ParseUint(u.Gid, 10, 32) if err != nil { return &execUser, err } diff --git a/test/system/030-run.bats b/test/system/030-run.bats index 82bbd67d13..a1e26805c2 100644 --- a/test/system/030-run.bats +++ b/test/system/030-run.bats @@ -786,6 +786,17 @@ EOF user=$(id -un) run_podman 1 run --rm $IMAGE grep $user /etc/passwd run_podman run --hostuser=$user --rm $IMAGE grep $user /etc/passwd + + # find a user with a uid > 100 that is a valid octal + # Issue #19800 + octal_user=$(awk -F\: '$1!="nobody" && $3>100 && $3~/^[0-7]+$/ {print $1 " " $3; exit}' /etc/passwd) + # test only if a valid user was found + if test -n "$octal_user"; then + read octal_username octal_userid <<< $octal_user + run_podman run --user=$octal_username --hostuser=$octal_username --rm $IMAGE id -u + is "$output" "$octal_userid" + fi + user=$(id -u) run_podman run --hostuser=$user --rm $IMAGE grep $user /etc/passwd run_podman run --hostuser=$user --user $user --rm $IMAGE grep $user /etc/passwd