[Openmp-commits] [openmp] [OpenMP] Fix a potential memory buffer overflow (PR #67252)
Shilei Tian via Openmp-commits
openmp-commits at lists.llvm.org
Sun Sep 24 13:47:14 PDT 2023
https://github.com/shiltian updated https://github.com/llvm/llvm-project/pull/67252
>From 352ffe966ca48cf852a1f1486f13dddd59c8ccb9 Mon Sep 17 00:00:00 2001
From: Shilei Tian <i at tianshilei.me>
Date: Sun, 24 Sep 2023 16:47:04 -0400
Subject: [PATCH] [OpenMP] Fix a potential memory buffer overflow
the function `memcpy_s`. This patch fixes it.
Fix #67167.
---
openmp/runtime/src/kmp_environment.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/openmp/runtime/src/kmp_environment.cpp b/openmp/runtime/src/kmp_environment.cpp
index b35027b57f03db0..4def6ea9ac20943 100644
--- a/openmp/runtime/src/kmp_environment.cpp
+++ b/openmp/runtime/src/kmp_environment.cpp
@@ -407,9 +407,11 @@ ___kmp_env_blk_parse_unix(kmp_env_blk_t *block, // M: Env block to fill.
int i;
var = bulk;
for (i = 0; i < count; ++i) {
+ KMP_ASSERT(var < bulk + size);
+ [[maybe_unused]] size_t ssize = size - (var - bulk);
// Copy variable to bulk.
len = KMP_STRLEN(env[i]);
- KMP_MEMCPY_S(var, size, env[i], len + 1);
+ KMP_MEMCPY_S(var, ssize, env[i], len + 1);
// Save found variable in vars array.
__kmp_str_split(var, '=', &name, &value);
vars[i].name = name;
More information about the Openmp-commits
mailing list