]> git.ipfire.org Git - thirdparty/util-linux.git/commit
su: pass arguments after <user> to shell
authorcgoesche <cgoesc2@wgu.edu>
Sun, 2 Nov 2025 16:55:09 +0000 (11:55 -0500)
committercgoesche <cgoesc2@wgu.edu>
Mon, 3 Nov 2025 18:16:19 +0000 (13:16 -0500)
commitac0147fd14b348097c82c1c89a5417b582e26bad
treefeeca7adca05b7277a3b275ddab6d60e8e7f4a3a
parent56e2c86c2c7ea012b63cd896d9ca3daa34f19565
su: pass arguments after <user> to shell

The su(1) manpage describes how the arguments after <user>
are passed to the invoked shell. However this is empirically
wrong, as option flags after <user> are interpreted by su(1)
and will eventually never be passed or yield an error that
terminates the program due to an unrecognized option flag.

To fix this we can change getopt(3)'s scanning mode with a '+'
prefixed to 'optstring', this will make it so that getopt(3)
stops processing argv elements on the first occurrence of a
non-option argument, e.g. '-' or '<user>'.

Additionally, if the argument that directly follows '-' is an
option flag, su(1) will assume that this argument and the ones
that follow, are to be passed to a shell invoked by the root user.

Addresses: https://github.com/util-linux/util-linux/pull/1809
Signed-off-by: cgoesche <cgoesc2@wgu.edu>
login-utils/su-common.c