Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Unified Diff: nspr/pr/src/misc/prenv.c

Issue 1843333003: Update NSPR to 4.12 and NSS to 3.23 on iOS (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/nss.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: nspr/pr/src/misc/prenv.c
diff --git a/nspr/pr/src/misc/prenv.c b/nspr/pr/src/misc/prenv.c
index 4935f9dc78e65bbfda3cbe0edd861ef72e4dcd98..cc2e198b97823fffaaabdc26629a493c09fbc12d 100644
--- a/nspr/pr/src/misc/prenv.c
+++ b/nspr/pr/src/misc/prenv.c
@@ -4,10 +4,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <string.h>
+#include <stdlib.h>
#include "primpl.h"
#include "prmem.h"
#if defined(XP_UNIX)
+#include <unistd.h>
#if defined(DARWIN)
#if defined(HAVE_CRT_EXTERNS_H)
#include <crt_externs.h>
@@ -17,6 +19,11 @@ PR_IMPORT_DATA(char **) environ;
#endif /* DARWIN */
#endif /* XP_UNIX */
+#if !defined(HAVE_SECURE_GETENV) && defined(HAVE___SECURE_GETENV)
+#define secure_getenv __secure_getenv
+#define HAVE_SECURE_GETENV 1
+#endif
+
/* Lock used to lock the environment */
#if defined(_PR_NO_PREEMPT)
#define _PR_NEW_LOCK_ENV()
@@ -63,6 +70,34 @@ PR_IMPLEMENT(char*) PR_GetEnv(const char *var)
return ev;
}
+PR_IMPLEMENT(char*) PR_GetEnvSecure(const char *var)
+{
+#ifdef HAVE_SECURE_GETENV
+ char *ev;
+
+ if (!_pr_initialized) _PR_ImplicitInitialization();
+
+ _PR_LOCK_ENV();
+ ev = secure_getenv(var);
+ _PR_UNLOCK_ENV();
+
+ return ev;
+#else
+#ifdef XP_UNIX
+ /*
+ ** Fall back to checking uids and gids. This won't detect any other
+ ** privilege-granting mechanisms the platform may have. This also
+ ** can't detect the case where the process already called
+ ** setuid(geteuid()) and/or setgid(getegid()).
+ */
+ if (getuid() != geteuid() || getgid() != getegid()) {
+ return NULL;
+ }
+#endif /* XP_UNIX */
+ return PR_GetEnv(var);
+#endif /* HAVE_SECURE_GETENV */
+}
+
PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string)
{
PRIntn result;

Powered by Google App Engine
This is Rietveld 408576698