Skip to content

Commit 6a9a480

Browse files
vma/util: ASAN problem fix.
1 parent 0dc96e0 commit 6a9a480

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

src/vma/util/sys_vars.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,21 @@ int mce_sys_var::hex_to_cpuset(char *start, cpu_set_t *cpu_set)
276276
int mce_sys_var::env_to_cpuset(char *orig_start, cpu_set_t *cpu_set)
277277
{
278278
int ret;
279-
char* start = strdup(orig_start); // save the caller string from strtok destruction.
279+
CPU_ZERO(cpu_set);
280+
281+
int len = strlen(orig_start);
282+
if (len == 2 && orig_start[0] == '-' && orig_start[1] == '1') {
283+
return 0;
284+
}
280285

286+
char *start = strdup(orig_start); // save the caller string from strtok destruction.
281287
/*
282288
* We expect a hex number or comma delimited cpulist. Check for
283289
* starting characters of "0x" or "0X" and if present then parse
284290
* the string as a hexidecimal value, otherwise treat it as a
285291
* cpulist.
286292
*/
287-
if ((strlen(start) > 2) &&
293+
if ((len > 2) &&
288294
(start[0] == '0') &&
289295
((start[1] == 'x') || (start[1] == 'X'))) {
290296
ret = hex_to_cpuset(start + 2, cpu_set);

src/vma/util/utils.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,26 @@ int priv_read_file(const char *path, char *buf, size_t size, vlog_levels_t log_l
414414

415415
int read_file_to_int(const char *path, int default_value)
416416
{
417-
int value = -1;
418-
std::ifstream file_stream(path);
419-
if (!file_stream || !(file_stream >> value)) {
420-
__log_warn("ERROR while getting int from from file %s, we'll use default %d", path, default_value);
421-
return default_value;
417+
int fd, sz;
418+
char c[21] = {};
419+
420+
fd = open(path, O_RDONLY);
421+
if (fd >= 0) {
422+
sz = read(fd, c, 20);
423+
if (sz > 0) {
424+
int value;
425+
c[sz] = '\0';
426+
int n = sscanf(reinterpret_cast<const char *>(&c), "%d", &value);
427+
if (n == 1) {
428+
close(fd);
429+
return value;
430+
}
431+
}
432+
close(fd);
422433
}
423-
return value;
434+
435+
__log_warn("ERROR while getting int from from file %s, we'll use default %d", path, default_value);
436+
return default_value;
424437
}
425438

426439
int get_ifinfo_from_ip(const struct sockaddr& addr, char* ifname, uint32_t& ifflags)

0 commit comments

Comments
 (0)