Skip to content

Commit

Permalink
Merge pull request #82 from gerd-rausch/orabug28420119
Browse files Browse the repository at this point in the history
Fix ambiguous parsing of *node* entries in /sys.

Acked-by: Neil Horman <nhorman@tuxdriver.com>
  • Loading branch information
nhorman authored Oct 19, 2018
2 parents ca8c12f + 7214606 commit 0d0b930
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
11 changes: 8 additions & 3 deletions cputree.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,14 @@ static void do_one_cpu(char *path)
entry = readdir(dir);
if (!entry)
break;
if (strstr(entry->d_name, "node")) {
nodeid = strtoul(&entry->d_name[4], NULL, 10);
break;
if (strncmp(entry->d_name, "node", 4) == 0) {
char *end;
int num;
num = strtol(entry->d_name + 4, &end, 10);
if (!*end && num >= 0) {
nodeid = num;
break;
}
}
} while (entry);
closedir(dir);
Expand Down
5 changes: 4 additions & 1 deletion numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <dirent.h>

Expand Down Expand Up @@ -115,7 +116,9 @@ void build_numa_node_list(void)
entry = readdir(dir);
if (!entry)
break;
if ((entry->d_type == DT_DIR) && (strstr(entry->d_name, "node"))) {
if ((entry->d_type == DT_DIR) &&
(strncmp(entry->d_name, "node", 4) == 0) &&
isdigit(entry->d_name[4])) {
add_one_node(entry->d_name);
}
} while (entry);
Expand Down

0 comments on commit 0d0b930

Please sign in to comment.