aboutsummaryrefslogtreecommitdiffstats
path: root/lib/env.c
AgeCommit message (Collapse)AuthorFilesLines
2025-09-01autotools: cleanup tests to use libcommon.laKarel Zak1-1/+1
This change simplifies future test work. Signed-off-by: Karel Zak <kzak@redhat.com>
2025-06-26lib/strv: use ul_ prefix for strv functionsKarel Zak1-3/+3
The functions are originally from systemd/udev, so it's possible that during static linking, they may collide with other systemd-based components. Fixes: https://github.com/util-linux/util-linux/issues/3626 Signed-off-by: Karel Zak <kzak@redhat.com>
2025-05-20treewide: improve getauxval(AT_SECURE) usageKarel Zak1-2/+1
Let's enhance portability and readability slightly. Signed-off-by: Karel Zak <kzak@redhat.com>
2025-05-10lib/env, ...: use getauxval(AT_SECURE) for SUID checkMax Kellermann1-1/+2
Comparing effective and real uid/gid is not a proper way to check for SUID execution: 1. this does not consider file capabilities 2. this check breaks when NO_NEW_PRIVS is used as the Linux kernel resets effective ids during execve(); this means the check is false, but the process still has raised capabilities For more details about the NO_NEW_PRIVS problem, check this post and the surrounding thread: https://lore.kernel.org/lkml/20250509184105.840928-1-max.kellermann@ionos.com/ Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
2024-11-07nsenter: support empty environ[]Karel Zak1-0/+1
There is no error when the /proc/#/environ file does not contain any NAME=value items. Fixes: https://github.com/util-linux/util-linux/issues/3270 Signed-off-by: Karel Zak <kzak@redhat.com>
2024-09-04env: add env_list_add_getenv() and env_list_add_getenvs()Karel Zak1-1/+42
* Add env_list_add_getenv() to import a single variable from the environ[] array. The function may accept a default value if getenv() does not return anything. * Add env_list_add_getenvs() to import multiple variables from the environ[] array. Signed-off-by: Karel Zak <kzak@redhat.com>
2024-09-04env: cleanup env_list APIKarel Zak1-4/+4
* rename env_from_fd() to env_list_from_fd() * rename remove_entry() to ul_remove_entry() Signed-off-by: Karel Zak <kzak@redhat.com>
2024-09-04env: add "overwrite" argument to env_list_setenv()Karel Zak1-3/+3
Signed-off-by: Karel Zak <kzak@redhat.com>
2024-09-04env: save parsed variables into ul_env_listKarel Zak1-28/+59
The struct ul_env_list is currently only used to store the value of env when sanitizing environ[]. It would be beneficial to also use the functions related to ul_env_list for other purposes. In order to do this, it is important to keep the NAME and VALUE components separate. * Accept non-terminated name and value for env_list_add(). * Add env_list_add_from_string() to add item to the list from a "name=value" string. * Add env_list_add_variable() to add item to the list using separate "name" and "value" strings. * Update __sanitize_env() to use env_list_add_from_string(). * Modify the test to use "abc" as the value instead of copying the variable name (with '=') to the value. Signed-off-by: Karel Zak <kzak@redhat.com>
2023-09-22lib/env: fix function name remote_entry -> remove_entryThomas Weißschuh1-2/+2
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-09-22lib/env: avoid underflow of read_all_alloc() return valueThomas Weißschuh1-1/+1
read_all_alloc() returns a negative error on failure. When casting this to an unsigned type the failure check "< 1" will not work. Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-03-09lib/env: fix memory leak [coverity scan]Karel Zak1-4/+7
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-03-02nsenter: add --env for allowing environment variables inheritanceu23861-0/+24
This commit adds support for the -e or --env option in nsenter, allowing a new process to inherit the environment va If the option is not given, the environment variables will stay the same as in the current namespace. Example: Setup the namespace: $ docker run -d -e PROJECT='util linux' --rm alpine sleep 10000 cb0b69aa7aec $ docker inspect --format '{{ .State.Pid }}' cb0b69aa7aec 470012 Enter the namespace: $ nsenter --all -t 470012 --env env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=cb0b69aa7aec PROJECT=util linux HOME=/root Reviewed-by: Thomas Weißschuh <thomas@t-8ch.de> Reviewed-by: Karel Zak <kzak@redhat.com> Signed-off-by: u2386 <hugo.cavan2386@gmail.com>
2022-04-26lib: allow safe_getenv to work for non-root usersMike Gilbert1-3/+1
This allows users to override settings like BLKID_FILE, as is done in the e2fsprogs test suite. Bug: https://bugs.gentoo.org/839825 Fixes: 035507c84b53bceb143d0923e65916cbf90979c7 Signed-off-by: Mike Gilbert <floppym@gentoo.org>
2021-09-23lib/env: don't ignore failed mallocKarel Zak1-1/+3
Fixes: https://github.com/karelzak/util-linux/issues/1434 Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-04misc: fix typos [codespell]Samanta Navarro1-2/+2
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-10-06lib: add missing headers to .c filesKarel Zak1-4/+3
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-25lib/env: add function to save and restore unwanted variablesKarel Zak1-3/+100
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-04-22include/nls: remove unnecessary declarationKarel Zak1-1/+1
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-04-13include: add remove_entry() to env.hSami Kerola1-5/+6
A function to remove an command-line option argument, or environment variable. Requested-by: Karel Zak <kzak@redhat.com> Reference: https://github.com/karelzak/util-linux/pull/1003#discussion_r403988092 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13tests: add sanitize_env() checkSami Kerola1-0/+31
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14lib: remove _RLD_ from forbid environment variable listSami Kerola1-1/+0
The RLD environment variables are related to runtime linker vulnerability in TELNET on systems running Silicon Graphics IRIX. It is extremely unlikely current util-linux would be compiled on such system. Reference: http://www.cert.org/historical/advisories/CA-1995-14.cfm Reference: http://signatures.juniper.net/documentation/signatures/TELNET%3AEXPLOIT%3ASGI-RLD.html Refefence: http://www.polarhome.com/service/man/?qf=rld&tf=2&of=IRIX&sf=1 Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-02-06build-sys: test for secure_getenv() too.Cristian Rodríguez1-2/+3
In current glibc versions, internal __secure_getenv no longer exists and was replaced by secure_getenv() Signed-off-by: Cristian Rodríguez <crrodriguez@opensuse.org>
2013-02-06textual: spell and encode the name of Arkadiusz Miśkiewicz correctlyBenno Schulenberg1-1/+1
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2012-06-11build: fix redundant redeclaration warningsSami Kerola1-0/+2
env.c:24:15: warning: redundant redeclaration of 'environ' [-Wredundant-decls] su.c:81:15: warning: redundant redeclaration of 'environ' [-Wredundant-decls] fstab.c:581:14: warning: redundant redeclaration of 'strsignal' [-Wredundant-decls] kill.h:1:13: note: previous declaration of 'get_pids' was here kill.c:152:13: warning: redundant redeclaration of 'get_pids' [-Wredundant-decls] kill.c:142:5: warning: redundant redeclaration of 'main' [-Wredundant-decls] getopt.c:89:5: warning: redundant redeclaration of 'main' [-Wredundant-decls] agetty.c:536:15: warning: redundant redeclaration of 'optarg' [-Wredundant-decls] agetty.c:537:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls] script.c:161:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls] wall.c:96:13: warning: redundant redeclaration of 'optind' [-Wredundant-decls] libmount.h:362:26: note: previous declaration of 'mnt_update_get_fs' was here libmount.h:454:26: note: previous declaration of 'mnt_context_get_fs' was here mountP.h:383:26: warning: redundant redeclaration of 'mnt_context_get_fs' [-Wredundant-decls] mountP.h:398:26: warning: redundant redeclaration of 'mnt_update_get_fs' [-Wredundant-decls] Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-02build-sys: check HAVE_ definitions with #ifdef [smatch scan]Sami Kerola1-1/+1
Fix to `warning: undefined preprocessor identifier' messages. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-01-03lib: [env] consolidate safe_getenv() usageKarel Zak1-1/+35
Signed-off-by: Karel Zak <kzak@redhat.com>
2006-12-07Imported from util-linux-2.13-pre1 tarball.v2.13-pre1Karel Zak1-1/+1
2006-12-07Imported from util-linux-2.11b tarball.v2.11bKarel Zak1-1/+1
2006-12-07Imported from util-linux-2.9v tarball.v2.9vKarel Zak1-0/+73