summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5e6a4f7)
raw | patch | inline | side by side (parent: 5e6a4f7)
author | Florian Forster <octo@collectd.org> | |
Mon, 5 Sep 2016 08:35:22 +0000 (10:35 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Wed, 14 Sep 2016 18:28:58 +0000 (20:28 +0200) |
Since we allocate the buffer on the stack, this doesn't make sense:
Best case, the returned value is the same as the PATH_MAX define. Worst
case, the returned value is larger and we create a stack overflow.
Best case, the returned value is the same as the PATH_MAX define. Worst
case, the returned value is larger and we create a stack overflow.
src/hugepages.c | patch | blob | history |
diff --git a/src/hugepages.c b/src/hugepages.c
index 8573fc34d636bbb29cfb1dfd2eaa86e209079431..8e8391f464bf8a732ad037cae4a2918526f3e46d 100644 (file)
--- a/src/hugepages.c
+++ b/src/hugepages.c
struct dirent *result;
char path2[PATH_MAX];
struct entry_info e_info;
- long lim;
dir = opendir(path);
if (dir == NULL) {
return -1;
}
- errno = 0;
- if ((lim = pathconf(path, _PC_NAME_MAX)) == -1) {
- /* Limit not defined if errno == 0, otherwise error */
- if (errno != 0) {
- ERROR("%s: pathconf failed", g_plugin_name);
- closedir(dir);
- return -1;
- } else {
- lim = PATH_MAX;
- }
- }
-
/* read "hugepages-XXXXXkB" entries */
while ((result = readdir(dir)) != NULL) {
if (strncmp(result->d_name, hugepages_dir, sizeof(hugepages_dir) - 1)) {
}
/* /sys/devices/system/node/node?/hugepages/ */
- ssnprintf(path2, (size_t)lim, "%s/%s", path, result->d_name);
+ ssnprintf(path2, sizeof(path2), "%s/%s", path, result->d_name);
e_info.d_name = result->d_name;
e_info.node = node;
DIR *dir;
struct dirent *result;
char path[PATH_MAX];
- long lim;
dir = opendir(sys_node);
if (dir == NULL) {
return -1;
}
- errno = 0;
- if ((lim = pathconf(sys_node, _PC_NAME_MAX)) == -1) {
- /* Limit not defined if errno == 0, otherwise error */
- if (errno != 0) {
- ERROR("%s: pathconf failed", g_plugin_name);
- closedir(dir);
- return -1;
- } else {
- lim = PATH_MAX;
- }
- }
-
while ((result = readdir(dir)) != NULL) {
if (strncmp(result->d_name, node_string, sizeof(node_string) - 1)) {
/* not node dir */
continue;
}
- ssnprintf(path, (size_t)lim, sys_node_hugepages, result->d_name);
+ ssnprintf(path, sizeof(path), sys_node_hugepages, result->d_name);
read_syshugepages(path, result->d_name);
errno = 0;
}