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.
This commit is contained in:
parent
041d7f637f
commit
2f85740ecc
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: env.h,v 1.1 2010/11/14 18:11:42 tron Exp $ */
|
||||
/* $NetBSD: env.h,v 1.2 2010/11/14 22:04:36 tron Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2010 The NetBSD Foundation, Inc.
|
||||
|
@ -36,7 +36,7 @@
|
|||
#include "reentrant.h"
|
||||
|
||||
extern ssize_t __getenvslot(const char *name, size_t l_name, bool allocate);
|
||||
extern char *__findenv(const char *name, size_t l_name);
|
||||
extern char *__findenvvar(const char *name, size_t l_name);
|
||||
|
||||
#ifdef _REENTRANT
|
||||
extern bool __readlockenv(void);
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue