[Openmp-commits] [openmp] 103bb69 - [OpenMP] Fix a potential memory buffer overflow (#67252)

via Openmp-commits openmp-commits at lists.llvm.org
Fri Sep 29 09:41:37 PDT 2023


Author: Shilei Tian
Date: 2023-09-29T12:41:32-04:00
New Revision: 103bb69c04a9ce8aa1ea1bcee4acaa3703e46869

URL: https://github.com/llvm/llvm-project/commit/103bb69c04a9ce8aa1ea1bcee4acaa3703e46869
DIFF: https://github.com/llvm/llvm-project/commit/103bb69c04a9ce8aa1ea1bcee4acaa3703e46869.diff

LOG: [OpenMP] Fix a potential memory buffer overflow (#67252)

#67167 reports a potential memory overflow caused by the wrong size
passed to the function `memcpy_s`. This patch fixes it.

Fix #67167.

Added: 
    

Modified: 
    openmp/runtime/src/kmp_environment.cpp

Removed: 
    


################################################################################
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