summaryrefslogtreecommitdiff
path: root/libgomp/env.c
diff options
context:
space:
mode:
authorvries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>2017-06-27 15:51:37 +0000
committervries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>2017-06-27 15:51:37 +0000
commite9f3b6c964585958a7c8be18a832a77b6bba9c67 (patch)
treee0abf5f9fc8bcbed50120155f56b0f77255f8f87 /libgomp/env.c
parent3461db541e63afe7b06f08b02642bd519addba56 (diff)
downloadgcc-e9f3b6c964585958a7c8be18a832a77b6bba9c67.tar.gz
Use secure_getenv for GOMP_DEBUG
2017-06-27 Tom de Vries <tom@codesourcery.com> * env.c (parse_unsigned_long_1): Factor out of ... (parse_unsigned_long): ... here. (parse_int_1): Factor out of ... (parse_int): ... here. (parse_int_secure): New function. (initialize_env): Use parse_int_secure for GOMP_DEBUG. * secure_getenv.h: Factor out of ... * plugin/plugin-hsa.c: ... here. * testsuite/libgomp.oacc-c-c++-common/gomp-debug-env.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@249694 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgomp/env.c')
-rw-r--r--libgomp/env.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/libgomp/env.c b/libgomp/env.c
index ced752d18e4..802c73bb464 100644
--- a/libgomp/env.c
+++ b/libgomp/env.c
@@ -26,6 +26,7 @@
/* This file defines the OpenMP internal control variables and arranges
for them to be initialized from environment variables at startup. */
+#define _GNU_SOURCE
#include "libgomp.h"
#include "gomp-constants.h"
#include <limits.h>
@@ -58,6 +59,8 @@
#endif
#endif /* LIBGOMP_OFFLOADED_ONLY */
+#include "secure_getenv.h"
+
struct gomp_task_icv gomp_global_icv = {
.nthreads_var = 1,
.thread_limit_var = UINT_MAX,
@@ -171,15 +174,17 @@ parse_schedule (void)
}
/* Parse an unsigned long environment variable. Return true if one was
- present and it was successfully parsed. */
+ present and it was successfully parsed. If SECURE, use secure_getenv to the
+ environment variable. */
static bool
-parse_unsigned_long (const char *name, unsigned long *pvalue, bool allow_zero)
+parse_unsigned_long_1 (const char *name, unsigned long *pvalue, bool allow_zero,
+ bool secure)
{
char *env, *end;
unsigned long value;
- env = getenv (name);
+ env = (secure ? secure_getenv (name) : getenv (name));
if (env == NULL)
return false;
@@ -206,14 +211,23 @@ parse_unsigned_long (const char *name, unsigned long *pvalue, bool allow_zero)
return false;
}
+/* As parse_unsigned_long_1, but always use getenv. */
+
+static bool
+parse_unsigned_long (const char *name, unsigned long *pvalue, bool allow_zero)
+{
+ return parse_unsigned_long_1 (name, pvalue, allow_zero, false);
+}
+
/* Parse a positive int environment variable. Return true if one was
- present and it was successfully parsed. */
+ present and it was successfully parsed. If SECURE, use secure_getenv to the
+ environment variable. */
static bool
-parse_int (const char *name, int *pvalue, bool allow_zero)
+parse_int_1 (const char *name, int *pvalue, bool allow_zero, bool secure)
{
unsigned long value;
- if (!parse_unsigned_long (name, &value, allow_zero))
+ if (!parse_unsigned_long_1 (name, &value, allow_zero, secure))
return false;
if (value > INT_MAX)
{
@@ -224,6 +238,22 @@ parse_int (const char *name, int *pvalue, bool allow_zero)
return true;
}
+/* As parse_int_1, but use getenv. */
+
+static bool
+parse_int (const char *name, int *pvalue, bool allow_zero)
+{
+ return parse_int_1 (name, pvalue, allow_zero, false);
+}
+
+/* As parse_int_1, but use getenv_secure. */
+
+static bool
+parse_int_secure (const char *name, int *pvalue, bool allow_zero)
+{
+ return parse_int_1 (name, pvalue, allow_zero, true);
+}
+
/* Parse an unsigned long list environment variable. Return true if one was
present and it was successfully parsed. */
@@ -1207,7 +1237,7 @@ initialize_env (void)
gomp_global_icv.thread_limit_var
= thread_limit_var > INT_MAX ? UINT_MAX : thread_limit_var;
}
- parse_int ("GOMP_DEBUG", &gomp_debug_var, true);
+ parse_int_secure ("GOMP_DEBUG", &gomp_debug_var, true);
#ifndef HAVE_SYNC_BUILTINS
gomp_mutex_init (&gomp_managed_threads_lock);
#endif