Module Name: src
Committed By: tron
Date: Sun Nov 14 22:04:37 UTC 2010
Modified Files:
src/lib/libc/include: env.h
src/lib/libc/stdlib: _env.c getenv.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/include/env.h
cvs rdiff -u -r1.1 -r1.2 src/lib/libc/stdlib/_env.c
cvs rdiff -u -r1.34 -r1.35 src/lib/libc/stdlib/getenv.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/include/env.h
diff -u src/lib/libc/include/env.h:1.1 src/lib/libc/include/env.h:1.2
--- src/lib/libc/include/env.h:1.1 Sun Nov 14 18:11:42 2010
+++ src/lib/libc/include/env.h Sun Nov 14 22:04:36 2010
@@ -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);
Index: src/lib/libc/stdlib/_env.c
diff -u src/lib/libc/stdlib/_env.c:1.1 src/lib/libc/stdlib/_env.c:1.2
--- src/lib/libc/stdlib/_env.c:1.1 Sun Nov 14 18:11:43 2010
+++ src/lib/libc/stdlib/_env.c Sun Nov 14 22:04:36 2010
@@ -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 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 @@
/* 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 @@
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. */
Index: src/lib/libc/stdlib/getenv.c
diff -u src/lib/libc/stdlib/getenv.c:1.34 src/lib/libc/stdlib/getenv.c:1.35
--- src/lib/libc/stdlib/getenv.c:1.34 Sun Nov 14 20:37:02 2010
+++ src/lib/libc/stdlib/getenv.c Sun Nov 14 22:04:36 2010
@@ -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 @@
result = NULL;
if (__readlockenv()) {
- result = __findenv(name, l_name);
+ result = __findenvvar(name, l_name);
(void)__unlockenv();
}
@@ -96,7 +96,7 @@
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;