Skip to content

Conversation

frendsick
Copy link
Contributor

@frendsick frendsick commented Apr 21, 2025

This PR fixes a segmentation fault with the id -p command when the getlogin function is unable to determine the logged-in user.

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

fixes #7808

> 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
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@sylvestre
Copy link
Contributor

i think you can probably add a test here

frendsick and others added 2 commits April 22, 2025 22:06
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
@frendsick
Copy link
Contributor Author

I suggest trying to see if test_id_pretty_print now works in CI with the fallback skip removed in commit 499cb8c. The comments left on commit 48121da indicate that the command did not succeed at the time, and one possible reason could be the segfault that is now fixed. The whoami function used by tests nowadays seems to me that it should work with CI.

@frendsick frendsick requested a review from sylvestre April 22, 2025 20:25
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)

@sylvestre sylvestre merged commit 6ac444a into uutils:main Apr 23, 2025
70 checks passed
@frendsick frendsick deleted the fix/id-human-readable-segmentation-fault branch April 23, 2025 07:44
nickorlow pushed a commit to nickorlow/coreutils that referenced this pull request Jul 17, 2025
* id: Handle NULL pointer gracefully within `cstr2cow` macro

> 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

* id: Remove redundant std::ffi:: prefix from CStr

* id: Add comment for the null check

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>

* id: Remove skip for test that should not segfault anymore

Segfault fixed by 292fb92

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

id: Segmentation fault with -p flag
2 participants