From 8d405b265285c368df2e9cf1c14acee7532e0ee7 Mon Sep 17 00:00:00 2001 From: nancy.liao <huihui.liao@greentest.com.cn> Date: ćšć, 29 5æ 2025 18:14:38 +0800 Subject: [PATCH] Merge branch 'develop' of http://139.9.88.116:3000/r/module/open-license-manager into develop --- src/library/os/linux/os_linux.cpp | 26 ++++++++++++++------------ 1 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/library/os/linux/os_linux.cpp b/src/library/os/linux/os_linux.cpp index 2915808..b0edb3c 100644 --- a/src/library/os/linux/os_linux.cpp +++ b/src/library/os/linux/os_linux.cpp @@ -12,13 +12,14 @@ #include <sstream> #include "../os.h" #include "../../base/logger.h" +#include "../../base/string_utils.h" #include <mntent.h> #include <dirent.h> #include <sys/utsname.h> -#ifndef NDEBUG -#include <valgrind/memcheck.h> -#endif +// #ifndef NDEBUG +// #include <valgrind/memcheck.h> +// #endif //#ifdef USE_DISK_MODEL ///#define PARSE_ID_FUNC parse_disk_id @@ -30,6 +31,8 @@ #ifdef USE_DBUS #include <dbus-1.0/dbus/dbus.h> #endif + +using namespace license; /** *Usually uuid are hex number separated by "-". this method read up to 8 hex @@ -104,9 +107,9 @@ std::string cur_dev = blkid_file_content.substr(oldpos, pos); diskInfo.id = diskNum++; std::string device = cur_dev.substr(cur_dev.find_last_of(">") + 1); - strncpy(diskInfo.device, device.c_str(), MAX_PATH); + mstrlcpy(diskInfo.device, device.c_str(), MAX_PATH); std::string label = getAttribute(cur_dev, "PARTLABEL"); - strncpy(diskInfo.label, label.c_str(), 255); + mstrlcpy(diskInfo.label, label.c_str(), 255); std::string disk_sn = getAttribute(cur_dev, "UUID"); parseUUID(disk_sn.c_str(), diskInfo.disk_sn, sizeof(diskInfo.disk_sn)); std::string disk_type = getAttribute(cur_dev, "TYPE"); @@ -167,7 +170,7 @@ bool found = false; for (auto &diskInfo : disk_infos) { if (((int)(sym_stat.st_ino)) == diskInfo.id) { - strncpy(diskInfo.label, dir->d_name, 255 - 1); + mstrlcpy(diskInfo.label, dir->d_name, 255); diskInfo.label_initialized = true; LOG_DEBUG("Label for disk ino %d device %s, set to %s", sym_stat.st_ino, diskInfo.device, diskInfo.label); @@ -214,7 +217,7 @@ if (pos != std::string::npos) { device_name_s = device_name_s.substr(pos + 1); } - strncpy(tmpDiskInfo.device, device_name_s.c_str(), sizeof(tmpDiskInfo.device)); + mstrlcpy(tmpDiskInfo.device, device_name_s.c_str(), sizeof(tmpDiskInfo.device)); PARSE_ID_FUNC(dir->d_name, tmpDiskInfo.disk_sn, sizeof(tmpDiskInfo.disk_sn)); tmpDiskInfo.sn_initialized = true; tmpDiskInfo.label_initialized = false; @@ -365,12 +368,11 @@ strcat(proc_path, "/exe"); int ch = readlink(proc_path, path, MAX_PATH - 1); - if (ch != -1) { - path[ch] = '\0'; - strncpy(buffer, path, ch); - result = FUNC_RET_OK; - } else { + if (ch > MAX_PATH || ch < 0) { result = FUNC_RET_ERROR; + } else { + mstrlcpy(buffer, path, ch + 1); + result = FUNC_RET_OK; } return result; } -- Gitblit v1.9.1