Skip to content

Edge case in username fallback logic in clp-package build script #1371

@coderabbitai

Description

@coderabbitai

Description

An edge case exists in the username fallback logic in tools/docker-images/clp-package/build.sh at line 51:

user="${USER:-$(id -un 2>/dev/null || whoami 2>/dev/null || echo unknown)}"

When the username cannot be found on the system (e.g., the username is not specified in /etc/passwd), id -un may print the numeric user ID followed by a newline but exit with a non-zero code. Due to the || chaining, subsequent commands (whoami and echo unknown) continue to execute, causing their output to be appended, resulting in a multi-line string with line breaks embedded in the user variable.

Example scenario

id -un: Prints 123\n; Exits with non-0
whoami: Prints nothing; Exits with non-0
echo unknown: Prints "unknown"

Result: user becomes "123\nunknown"

This could lead to invalid Docker image tag names or unexpected behaviour in the build process.

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions