[Openmp-commits] [openmp] [OpenMP] Use secure_getenv when read OMPT library path (PR #208652)

Jan Patrick Lehr via Openmp-commits openmp-commits at lists.llvm.org
Fri Jul 10 01:24:11 PDT 2026


https://github.com/jplehr created https://github.com/llvm/llvm-project/pull/208652

An internal review flagged the use of `getenv` when reading the OMPT tool library path from the environment and passing it to the loader as a potential vuln.

This patch replaces the use of getenv in question with the use of secure_getenv on glibc platforms.
On non glibc platforms, no change is implemented.

>From 850f41be5ee4666c022efe9e081c7a62c937c279 Mon Sep 17 00:00:00 2001
From: JP Lehr <JanPatrick.Lehr at amd.com>
Date: Fri, 10 Jul 2026 02:44:54 -0500
Subject: [PATCH] [OpenMP] Use secure_getenv when read OMPT library path

An internal review flagged the use of `getenv` when reading the OMPT
tool library path from the environment and passing it to the loader as a
potential vuln.

This patch replaces the use of getenv in question with the use of
secure_getenv on glibc platforms.
On non glibc platforms, no change is implemented.
---
 openmp/runtime/src/ompt-general.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/openmp/runtime/src/ompt-general.cpp b/openmp/runtime/src/ompt-general.cpp
index a708a8d76fcf4..1682f7e74bd14 100644
--- a/openmp/runtime/src/ompt-general.cpp
+++ b/openmp/runtime/src/ompt-general.cpp
@@ -60,6 +60,12 @@
 static FILE *verbose_file;
 static int verbose_init;
 
+#if defined(__GLIBC__)
+#define OMPT_GETENV secure_getenv
+#else
+#define OMPT_GETENV getenv
+#endif
+
 /*****************************************************************************
  * types
  ****************************************************************************/
@@ -281,7 +287,7 @@ ompt_try_start_tool(unsigned int omp_version, const char *runtime_version) {
 
   // Try tool-libraries-var ICV
   OMPT_VERBOSE_INIT_CONTINUED_PRINT("Failed.\n");
-  const char *tool_libs = getenv("OMP_TOOL_LIBRARIES");
+  const char *tool_libs = OMPT_GETENV("OMP_TOOL_LIBRARIES");
   if (tool_libs) {
     OMPT_VERBOSE_INIT_PRINT("Searching tool libraries...\n");
     OMPT_VERBOSE_INIT_PRINT("OMP_TOOL_LIBRARIES = %s\n", tool_libs);



More information about the Openmp-commits mailing list