X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fturbostat.c;h=6fa172d0b666fd1b3c612fcb3d4423215ab45257;hb=3228135fb721281f1134cb4e17c583c8cdfc1909;hp=cc0be207087b389979d9dd6e69bf4179792a4753;hpb=10692e3f990377ad4e0918977d3f9431b222d1bc;p=collectd.git diff --git a/src/turbostat.c b/src/turbostat.c index cc0be207..6fa172d0 100644 --- a/src/turbostat.c +++ b/src/turbostat.c @@ -262,6 +262,7 @@ enum return_values { ERR_CPU_ALLOC, ERR_NOT_ROOT, UNSUPPORTED_CPU, + ERR_PATH_TOO_LONG, }; @@ -1069,11 +1070,16 @@ parse_int_file(const char *fmt, ...) va_list args; char path[PATH_MAX]; FILE *filep; - int value; + int len, value; va_start(args, fmt); - vsnprintf(path, sizeof(path), fmt, args); + len = vsnprintf(path, sizeof(path), fmt, args); va_end(args); + if (len < 0 || len >= PATH_MAX) { + ERROR("Turbostat plugin: path truncated: '%s'", path); + return -ERR_PATH_TOO_LONG; + } + filep = fopen(path, "r"); if (!filep) { ERROR("Turbostat plugin: Failed to open '%s'", path);