[Openmp-commits] [PATCH] D82452: [OpenMP][Tool] Fix buffer overflow in ompt-multiplex.h

Joachim Protze via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Jun 24 04:49:56 PDT 2020


protze.joachim created this revision.
protze.joachim added a reviewer: ronlieb.
protze.joachim added a project: OpenMP.
Herald added subscribers: sstefan1, guansong, yaxunl.
Herald added a reviewer: jdoerfert.

The code failed to allocate memory for the terminating 0-byte.

Reported by: @ronlieb


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82452

Files:
  openmp/tools/multiplex/ompt-multiplex.h


Index: openmp/tools/multiplex/ompt-multiplex.h
===================================================================
--- openmp/tools/multiplex/ompt-multiplex.h
+++ openmp/tools/multiplex/ompt-multiplex.h
@@ -26,6 +26,7 @@
 #include <omp.h>
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 
 static ompt_set_callback_t ompt_multiplex_set_callback;
 static ompt_get_task_info_t ompt_multiplex_get_task_info;
@@ -1040,12 +1041,11 @@
   const char *tool_libs = getenv(CLIENT_TOOL_LIBRARIES_VAR);
   if (tool_libs) {
     // copy environement variable
-    char *tool_libs_buffer = (char *)malloc(sizeof(char) * strlen(tool_libs));
+    char *tool_libs_buffer = strdup(tool_libs);
     if (!tool_libs_buffer) {
-      printf("malloc Error\n");
+      printf("strdup Error (%i)\n", errno);
       exit(-1);
     }
-    strcpy(tool_libs_buffer, tool_libs);
 
     int progress = 0;
     while (progress < strlen(tool_libs)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82452.272975.patch
Type: text/x-patch
Size: 931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200624/02511dbe/attachment.bin>


More information about the Openmp-commits mailing list