From 8883af90f807c9c6edb14a7cb2801b761f3d072e Mon Sep 17 00:00:00 2001 From: Kirill Okhotnikov Date: Thu, 13 Nov 2025 08:39:34 -0500 Subject: [PATCH] vma/util: ASAN problem fix. --- src/vma/util/sys_vars.cpp | 10 ++++++++-- src/vma/util/utils.cpp | 25 +++++++++++++++++++------ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/vma/util/sys_vars.cpp b/src/vma/util/sys_vars.cpp index f59327ca3..b2c72c4a7 100644 --- a/src/vma/util/sys_vars.cpp +++ b/src/vma/util/sys_vars.cpp @@ -276,15 +276,21 @@ int mce_sys_var::hex_to_cpuset(char *start, cpu_set_t *cpu_set) int mce_sys_var::env_to_cpuset(char *orig_start, cpu_set_t *cpu_set) { int ret; - char* start = strdup(orig_start); // save the caller string from strtok destruction. + int len = strlen(orig_start); + if (len == 2 && orig_start[0] == '-' && orig_start[1] == '1') { + CPU_ZERO(cpu_set); + return 0; + } + + char *start = strdup(orig_start); // save the caller string from strtok destruction. /* * We expect a hex number or comma delimited cpulist. Check for * starting characters of "0x" or "0X" and if present then parse * the string as a hexidecimal value, otherwise treat it as a * cpulist. */ - if ((strlen(start) > 2) && + if ((len > 2) && (start[0] == '0') && ((start[1] == 'x') || (start[1] == 'X'))) { ret = hex_to_cpuset(start + 2, cpu_set); diff --git a/src/vma/util/utils.cpp b/src/vma/util/utils.cpp index 4c31db0a1..b127a8b2f 100644 --- a/src/vma/util/utils.cpp +++ b/src/vma/util/utils.cpp @@ -414,13 +414,26 @@ int priv_read_file(const char *path, char *buf, size_t size, vlog_levels_t log_l int read_file_to_int(const char *path, int default_value) { - int value = -1; - std::ifstream file_stream(path); - if (!file_stream || !(file_stream >> value)) { - __log_warn("ERROR while getting int from from file %s, we'll use default %d", path, default_value); - return default_value; + int fd, sz; + char c[21] = {}; + + fd = open(path, O_RDONLY); + if (fd >= 0) { + sz = read(fd, c, 20); + if (sz > 0) { + int value; + c[sz] = '\0'; + int n = sscanf(c, "%d", &value); + if (n == 1) { + close(fd); + return value; + } + } + close(fd); } - return value; + + __log_warn("ERROR while getting int from from file %s, we'll use default %d", path, default_value); + return default_value; } int get_ifinfo_from_ip(const struct sockaddr& addr, char* ifname, uint32_t& ifflags)