these functions are safer

This commit is contained in:
2026-06-24 20:20:36 +02:00
parent b46f457afc
commit 1099bb6688

View File

@@ -69,10 +69,12 @@ inline char *pretty_bytes(const uint64_t bytes, int8_t start_suffix, char *buf,
/* path has to have at least 8 free chars at the end for glob */
int get_hwmon_dir(char *path, const size_t bufsz) {
glob_t g;
strncat(path, "/hwmon*", 10);
if (strlcat(path, "/hwmon*", bufsz) >= bufsz)
return -1;
if (glob(path, 0, NULL, &g) == 0) {
strncpy(path, g.gl_pathv[0], bufsz); // same size as hwmon length, careful
strlcpy(path, g.gl_pathv[0], bufsz); // same size as hwmon length, careful
globfree(&g);
return 0;
}