Skip to content

id: Segmentation fault with -p flag #7808

@frendsick

Description

@frendsick

The id -p command can cause a segmentation fault when it is invoked without any users as arguments.

$ target/release/id -p
Segmentation fault (core dumped)
$ target/release/id -p root
uid     root
groups  root

The segmentation fault happens when the getlogin function call returns a NULL pointer. The cstr2cow macro fails as it is invoked with a NULL pointer instead of a valid C string.

getlogin() returns a pointer to a string containing the name of the user logged in on the controlling terminal of the process, or a NULL pointer if this information cannot be determined.

Ref: https://linux.die.net/man/3/getlogin

Environment

  • cargo --version: cargo 1.88.0-nightly (d811228b1 2025-04-15)
  • OS: Ubuntu 22.04.5 LTS on Windows 10 x86_64
  • Kernel: 5.15.167.4-microsoft-standard-WSL2
  • Shell: bash 5.1.16
  • Terminal: Windows Terminal

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions