Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc 1.) Rename internal function __findvar() to __finde...
details: https://anonhg.NetBSD.org/src/rev/8bbc3b4e9c7d
branches: trunk
changeset: 758749:8bbc3b4e9c7d
user: tron <tron%NetBSD.org@localhost>
date: Sun Nov 14 22:04:36 2010 +0000
description:
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:
lib/libc/include/env.h | 4 ++--
lib/libc/stdlib/_env.c | 30 ++++++++++++++++++++++++++++--
lib/libc/stdlib/getenv.c | 8 ++++----
3 files changed, 34 insertions(+), 8 deletions(-)
diffs (119 lines):
diff -r ef97ff91d966 -r 8bbc3b4e9c7d lib/libc/include/env.h
--- a/lib/libc/include/env.h Sun Nov 14 20:53:54 2010 +0000
+++ b/lib/libc/include/env.h Sun Nov 14 22:04:36 2010 +0000
@@ -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);
diff -r ef97ff91d966 -r 8bbc3b4e9c7d lib/libc/stdlib/_env.c
--- a/lib/libc/stdlib/_env.c Sun Nov 14 20:53:54 2010 +0000
+++ b/lib/libc/stdlib/_env.c Sun Nov 14 22:04:36 2010 +0000
@@ -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. */
diff -r ef97ff91d966 -r 8bbc3b4e9c7d lib/libc/stdlib/getenv.c
--- a/lib/libc/stdlib/getenv.c Sun Nov 14 20:53:54 2010 +0000
+++ b/lib/libc/stdlib/getenv.c Sun Nov 14 22:04:36 2010 +0000
@@ -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;
Home |
Main Index |
Thread Index |
Old Index