Browse Source

add secure_getenv() function

Waldemar Brodkorb 7 years ago
parent
commit
50dd36a50a
3 changed files with 10 additions and 4 deletions
  1. 1 3
      include/stdlib.h
  2. 1 1
      libc/stdlib/Makefile.in
  3. 8 0
      libc/stdlib/secure_getenv.c

+ 1 - 3
include/stdlib.h

@@ -575,12 +575,10 @@ extern char *getenv (const char *__name) __THROW __nonnull ((1)) __wur;
 libc_hidden_proto(getenv)
 __END_NAMESPACE_STD
 
-#if 0
 /* This function is similar to the above but returns NULL if the
    programs is running with SUID or SGID enabled.  */
-extern char *__secure_getenv (const char *__name)
+extern char *secure_getenv (const char *__name)
      __THROW __nonnull ((1)) __wur;
-#endif
 
 #if defined __USE_SVID || defined __USE_XOPEN
 /* The SVID says this is in <stdio.h>, but this seems a better place.	*/

+ 1 - 1
libc/stdlib/Makefile.in

@@ -17,7 +17,7 @@ CSRC-y := \
 	lldiv.c getpt.c drand48-iter.c jrand48.c \
 	jrand48_r.c lcong48.c lrand48.c lrand48_r.c mrand48.c mrand48_r.c nrand48.c \
 	nrand48_r.c rand_r.c srand48.c srand48_r.c seed48.c seed48_r.c \
-	a64l.c l64a.c __uc_malloc.c
+	a64l.c l64a.c __uc_malloc.c secure_getenv.c
 CSRC-$(UCLIBC_SUSV2_LEGACY) += valloc.c
 CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_memalign.c
 CSRC-$(UCLIBC_HAS_PTY) += grantpt.c unlockpt.c ptsname.c

+ 8 - 0
libc/stdlib/secure_getenv.c

@@ -0,0 +1,8 @@
+
+#include <stdlib.h>
+
+char *secure_getenv(const char *name) {
+	if (issetugid()) return NULL;
+	return getenv(name);
+}
+