]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: fix win32 event log source
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Wed, 17 Feb 2021 12:49:02 +0000 (12:49 +0000)
committerJason Dillaman <dillaman@redhat.com>
Tue, 23 Feb 2021 15:08:26 +0000 (10:08 -0500)
The Windows "get_process_name" function uses the input buffer
to store the entire executable path, while the caller only
expects the filename.

The "get_process_name_cpp" function is using an insufficient
buffer, for which reason it will return "(unknown)" when the
executable path exceeds 32 characters.

Windows event log entries have the wrong source because of this.

We'll update "get_process_name" to use a separate buffer for the
full executable path and avoid requesting a larger buffer than
actually needed.

Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
(cherry picked from commit 86c7c2f5be96e80d492447d6582131f1b2d3438d)

src/common/code_environment.cc

index a821dfcdeace1adf6379af7495a2265641ea878c..c8cf82e55087588dc500de3009d23ae4d45d71a0 100644 (file)
@@ -87,19 +87,23 @@ int get_process_name(char *buf, int len)
     return -EINVAL;
   }
 
-  int length = GetModuleFileNameA(nullptr, buf, len);
+  char full_path[MAX_PATH];
+  int length = GetModuleFileNameA(nullptr, full_path, sizeof(full_path));
   if (length <= 0)
     return -ENOSYS;
 
-  char* start = strrchr(buf, '\\');
+  char* start = strrchr(full_path, '\\');
   if (!start)
     return -ENOSYS;
   start++;
   char* end = strstr(start, ".exe");
   if (!end)
     return -ENOSYS;
+  if (len <= end - start) {
+    return -ENAMETOOLONG;
+  }
 
-  memmove(buf, start, end - start);
+  memcpy(buf, start, end - start);
   buf[end - start] = '\0';
   return 0;
 }