]> git.ipfire.org Git - thirdparty/systemd.git/commit
user-util: stop mangling groupname in get_group_creds
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Tue, 19 May 2026 15:59:57 +0000 (17:59 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 21 May 2026 16:02:05 +0000 (18:02 +0200)
commit3ecd6b69cff6e7209ff97f7e7e04ea37268b22c5
treef2db30a7068d1333b2c012520a9af2a5399ca43e
parent3d0a05dcc36eef148b95651bdc537f64bd9aa204
user-util: stop mangling groupname in get_group_creds

The param was input/output, which is unexpected and confusing and
actually made most callers much more complicated than they needed to be.
The function was playing fast and loose with the return value. In some
cases it was returning a static string, which would be completely fine.
But in other case it was returning a pointer into the getgrgid static
buffer, i.e. that return value could be overwritten. AFAICT, this didn't
matter in any of the callers, but we shouldn't do that anyway.

So use a separate output param with an allocated string that the caller
is responsible for.

It turns out that all callers pass NULL (outside of tests) and zero for
flags. So the function _could_ be simplified. But get_user_creds is
called with all the params actually used, and I think having the the
functions so different wouldn't be nice. I first wrote a commit to
drop the unused params, but then I discarded it.

The error message in exec-invoke.c is fixed.
src/basic/user-util.c
src/basic/user-util.h
src/core/exec-invoke.c
src/core/scope.c
src/core/socket.c
src/run/run.c
src/test/test-user-util.c
src/tmpfiles/tmpfiles.c