[Openmp-commits] [openmp] r248588 - Fix memory corruption in Windows debug library

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Fri Sep 25 10:23:18 PDT 2015


Author: jlpeyton
Date: Fri Sep 25 12:23:17 2015
New Revision: 248588

URL: http://llvm.org/viewvc/llvm-project?rev=248588&view=rev
Log:
Fix memory corruption in Windows debug library

This patch adjusts the buffer size when reducing the buffer used for printing.
This solves the memory corruption in Windows debug library, and potential
memory corruption in other builds.

Modified:
    openmp/trunk/runtime/src/kmp_affinity.cpp
    openmp/trunk/runtime/src/kmp_alloc.c

Modified: openmp/trunk/runtime/src/kmp_affinity.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_affinity.cpp?rev=248588&r1=248587&r2=248588&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_affinity.cpp (original)
+++ openmp/trunk/runtime/src/kmp_affinity.cpp Fri Sep 25 12:23:17 2015
@@ -66,13 +66,13 @@ __kmp_affinity_print_mask(char *buf, int
         }
     }
     if (i == KMP_CPU_SETSIZE) {
-        KMP_SNPRINTF(scan, buf_len, "{<empty>}");
+        KMP_SNPRINTF(scan, end-scan+1, "{<empty>}");
         while (*scan != '\0') scan++;
         KMP_ASSERT(scan <= end);
         return buf;
     }
 
-    KMP_SNPRINTF(scan, buf_len, "{%ld", (long)i);
+    KMP_SNPRINTF(scan, end-scan+1, "{%ld", (long)i);
     while (*scan != '\0') scan++;
     i++;
     for (; i < KMP_CPU_SETSIZE; i++) {
@@ -89,14 +89,14 @@ __kmp_affinity_print_mask(char *buf, int
         if (end - scan < 15) {
            break;
         }
-        KMP_SNPRINTF(scan, buf_len, ",%-ld", (long)i);
+        KMP_SNPRINTF(scan, end-scan+1, ",%-ld", (long)i);
         while (*scan != '\0') scan++;
     }
     if (i < KMP_CPU_SETSIZE) {
-        KMP_SNPRINTF(scan, buf_len,  ",...");
+        KMP_SNPRINTF(scan, end-scan+1,  ",...");
         while (*scan != '\0') scan++;
     }
-    KMP_SNPRINTF(scan, buf_len, "}");
+    KMP_SNPRINTF(scan, end-scan+1, "}");
     while (*scan != '\0') scan++;
     KMP_ASSERT(scan <= end);
     return buf;

Modified: openmp/trunk/runtime/src/kmp_alloc.c
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_alloc.c?rev=248588&r1=248587&r2=248588&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_alloc.c (original)
+++ openmp/trunk/runtime/src/kmp_alloc.c Fri Sep 25 12:23:17 2015
@@ -1178,7 +1178,7 @@ bufdump(  kmp_info_t *th, void *buf )
         }
 
         for (i = 0; i < l; i++) {
-            (void) KMP_SNPRINTF(bhex + i * 3, sizeof(bhex), "%02X ", bdump[i]);
+            (void) KMP_SNPRINTF(bhex + i * 3, sizeof(bhex) - i * 3, "%02X ", bdump[i]);
             if (bdump[i] > 0x20 && bdump[i] < 0x7F)
                 bascii[ i ] = bdump[ i ];
             else




More information about the Openmp-commits mailing list