summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authortron <tron@NetBSD.org>2010-11-14 22:04:36 +0000
committertron <tron@NetBSD.org>2010-11-14 22:04:36 +0000
commit2f85740ecc6040e4c1e359fe07e07def79d3732a (patch)
tree38bc87f05d53fd46c17194faa701e689e9fc7af9 /lib/libc/stdlib
parent041d7f637f00642465feaba537fab32473db97dc (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')
-rw-r--r--lib/libc/stdlib/_env.c30
-rw-r--r--lib/libc/stdlib/getenv.c8
2 files changed, 32 insertions, 6 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. */
diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c
index f9b81fca697..ccd52e77ffb 100644
--- a/lib/libc/stdlib/getenv.c
+++ b/lib/libc/stdlib/getenv.c
@@ -1,4 +1,4 @@
-/* $NetBSD: getenv.c,v 1.34 2010/11/14 20:37:02 tron Exp $ */
+/* $NetBSD: getenv.c,v 1.35 2010/11/14 22:04:36 tron Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)getenv.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: getenv.c,v 1.34 2010/11/14 20:37:02 tron Exp $");
+__RCSID("$NetBSD: getenv.c,v 1.35 2010/11/14 22:04:36 tron Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -71,7 +71,7 @@ getenv(const char *name)
result = NULL;
if (__readlockenv()) {
- result = __findenv(name, l_name);
+ result = __findenvvar(name, l_name);
(void)__unlockenv();
}
@@ -96,7 +96,7 @@ getenv_r(const char *name, char *buf, size_t len)
if (__readlockenv()) {
const char *value;
- value = __findenv(name, l_name);
+ value = __findenvvar(name, l_name);
if (value != NULL) {
if (strlcpy(buf, value, len) < len) {
rv = 0;