From: Lucian Petrut Date: Wed, 17 Feb 2021 12:49:02 +0000 (+0000) Subject: common: fix win32 event log source X-Git-Tag: v17.1.0~2883^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=86c7c2f5be96e80d492447d6582131f1b2d3438d;p=ceph-ci.git common: fix win32 event log source 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 --- diff --git a/src/common/code_environment.cc b/src/common/code_environment.cc index a821dfcdeac..c8cf82e5508 100644 --- a/src/common/code_environment.cc +++ b/src/common/code_environment.cc @@ -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; }