From 574f59b8f5b5ef54a9d3f7bf1c52c28e1c6dd16b Mon Sep 17 00:00:00 2001 From: Drath Date: Mon, 11 May 2026 11:01:37 +0000 Subject: [PATCH] make it take size after all --- include/utils.h | 6 +++--- src/cpu.c | 2 +- src/gpu.c | 2 +- src/sys.c | 2 +- src/utils.c | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/utils.h b/include/utils.h index 4bcbe26..91e1b79 100644 --- a/include/utils.h +++ b/include/utils.h @@ -1,5 +1,5 @@ -#ifndef UTILS_H -#define UTILS_H +#ifndef LINUXSMARTIE_UTILS_H +#define LINUXSMARTIE_UTILS_H #include #include @@ -31,7 +31,7 @@ char *pretty_bytes(uint64_t bytes, int8_t start_suffix, char *buf, size_t bufsz) bool file_exists(const char *path); -int get_hwmon_dir(char *path); +int get_hwmon_dir(char *path, size_t bufsz); size_t read_file(const char *path, char *buffer, size_t n); diff --git a/src/cpu.c b/src/cpu.c index ca1763c..e4622f6 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -12,7 +12,7 @@ void cpu_detect(struct cpu_sensors_t *t, const char *pci_dev) { t->num_cores = sysconf(_SC_NPROCESSORS_ONLN); snprintf(t->hwmon, sizeof(t->hwmon), "/sys/bus/pci/devices/%s/hwmon", pci_dev); - const int ret = get_hwmon_dir(t->hwmon); + const int ret = get_hwmon_dir(t->hwmon, sizeof(t->hwmon)); if (ret != 0) { t->hwmon[0] = '\0'; applog(LOG_WRN, "Detected %d cores, module enum #%d. Can't get hwmon path, skipping", t->num_cores, t->module); diff --git a/src/gpu.c b/src/gpu.c index 97938d4..a9ae503 100644 --- a/src/gpu.c +++ b/src/gpu.c @@ -12,7 +12,7 @@ const uint16_t max_metrics_length = 512; // length of the metrics buffer void gpu_detect(struct gpu_sensors_t *t, const char *pci) { snprintf(t->hwmon, sizeof(t->hwmon), "/sys/bus/pci/devices/%s/hwmon", pci); - const int ret = get_hwmon_dir(t->hwmon); + const int ret = get_hwmon_dir(t->hwmon, sizeof(t->hwmon)); if (ret != 0) { t->hwmon[0] = '\0'; applog(LOG_WRN, "Detected GPU hwmon"); diff --git a/src/sys.c b/src/sys.c index 09f08a9..56039c1 100644 --- a/src/sys.c +++ b/src/sys.c @@ -71,7 +71,7 @@ void sys_get_network(struct network_t *network) { void sys_detect(struct syssensors_t *s, const char *platform) { snprintf(s->hwmon, sizeof(s->hwmon), "/sys/devices/platform/%s/hwmon", platform); - const int ret = get_hwmon_dir(s->hwmon); + const int ret = get_hwmon_dir(s->hwmon, sizeof(s->hwmon)); if (ret != 0) { s->hwmon[0] = '\0'; applog(LOG_WRN, "Can't open system hwmon. Kernel params added? Module loaded? See README"); diff --git a/src/utils.c b/src/utils.c index 7a74cf5..1414378 100644 --- a/src/utils.c +++ b/src/utils.c @@ -55,12 +55,12 @@ inline bool file_exists(const char *path) { } /* path has to have at least 8 free chars at the end for glob */ -int get_hwmon_dir(char *path) { +int get_hwmon_dir(char *path, const size_t bufsz) { glob_t g; strncat(path, "/hwmon*", 10); if (glob(path, 0, NULL, &g) == 0) { - strncpy(path, g.gl_pathv[0], 128); // bug prone, careful + strncpy(path, g.gl_pathv[0], bufsz); // same size as hwmon length, careful globfree(&g); return 0; }