diff options
| author | tron <tron@NetBSD.org> | 2010-11-14 22:04:36 +0000 |
|---|---|---|
| committer | tron <tron@NetBSD.org> | 2010-11-14 22:04:36 +0000 |
| commit | 2f85740ecc6040e4c1e359fe07e07def79d3732a (patch) | |
| tree | 38bc87f05d53fd46c17194faa701e689e9fc7af9 /lib/libc/stdlib/_env.c | |
| parent | 041d7f637f00642465feaba537fab32473db97dc (diff) | |
1.) Rename internal function __findvar() to __findenvvar().
2.) Add a wrapper function __findenv() which implements the previous
*internal* interface. It turns out that ld.elf_so(1) and pthread(3)
both use it.
Stripping e.g. "LD_LIBRARY_PATH" from the environment while running
setuid binaries works again now.
Diffstat (limited to 'lib/libc/stdlib/_env.c')
| -rw-r--r-- | lib/libc/stdlib/_env.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/libc/stdlib/_env.c b/lib/libc/stdlib/_env.c index 67f4c78d670..80aa092e24c 100644 --- a/lib/libc/stdlib/_env.c +++ b/lib/libc/stdlib/_env.c @@ -1,4 +1,4 @@ -/* $NetBSD: _env.c,v 1.1 2010/11/14 18:11:43 tron Exp $ */ +/* $NetBSD: _env.c,v 1.2 2010/11/14 22:04:36 tron Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -33,6 +33,7 @@ #include <assert.h> #include <errno.h> +#include <limits.h> #include <stdlib.h> #include <stddef.h> #include <string.h> @@ -77,6 +78,12 @@ static size_t allocated_environ_size; static rwlock_t env_lock = RWLOCK_INITIALIZER; #endif +/* Compatibility function. */ +char *__findenv(const char *name, int *offsetp); + +__warn_references(__findenv, + "warning: __findenv is an internal obsolete function.") + /* Our initialization function. */ void __libc_env_init(void); @@ -268,7 +275,7 @@ __getenvslot(const char *name, size_t l_name, bool allocate) /* Find a string in the environment. */ char * -__findenv(const char *name, size_t l_name) +__findenvvar(const char *name, size_t l_name) { ssize_t offset; @@ -276,6 +283,25 @@ __findenv(const char *name, size_t l_name) return (offset != -1) ? environ[offset] + l_name + 1 : NULL; } +/* Compatibility interface, do *not* call this function. */ +char * +__findenv(const char *name, int *offsetp) +{ + size_t l_name; + ssize_t offset; + + l_name = __envvarnamelen(name, false); + if (l_name == 0) + return NULL; + + offset = __getenvslot(name, l_name, false); + if (offset < 0 || offset > INT_MAX) + return NULL; + + *offsetp = (int)offset; + return environ[offset] + l_name + 1; +} + #ifdef _REENTRANT /* Lock the environment for read. */ |
