diff options
| author | Len Brown <len.brown@intel.com> | 2026-05-04 15:38:34 -0400 |
|---|---|---|
| committer | Len Brown <len.brown@intel.com> | 2026-05-24 10:26:22 -0400 |
| commit | 1c996a37fd244d19e5dbb715328c1676e28ef607 (patch) | |
| tree | f36c136ab00e937148bb757ab5fb264ed6cf5611 | |
| parent | f88e0542da4268bf6f7a5fa250aa6d61b2dce128 (diff) | |
| download | linux-next-1c996a37fd244d19e5dbb715328c1676e28ef607.tar.gz linux-next-1c996a37fd244d19e5dbb715328c1676e28ef607.zip | |
tools/power turbostat: pmt: Improve sscanf() hygiene
Explicitly check sscanf() return values for number of matches,
and handle EOF (-1).
Defensive programming -- not an issue seen by users.
Fixes: 4265a86582ea ("tools/power turbostat: Add PMT directory iterator helper")
Assisted-by: Claude: Claude Sonnet 4.6
Signed-off-by: Len Brown <len.brown@intel.com>
| -rw-r--r-- | tools/power/x86/turbostat/turbostat.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c index 6819b70e0d56..4ad7cb1df5c5 100644 --- a/tools/power/x86/turbostat/turbostat.c +++ b/tools/power/x86/turbostat/turbostat.c @@ -2011,15 +2011,17 @@ int pmt_telemdir_filter(const struct dirent *e) { unsigned int dummy; - return sscanf(e->d_name, "telem%u", &dummy); + return (sscanf(e->d_name, "telem%u", &dummy) == 1); } int pmt_telemdir_sort(const struct dirent **a, const struct dirent **b) { unsigned int aidx = 0, bidx = 0; - sscanf((*a)->d_name, "telem%u", &aidx); - sscanf((*b)->d_name, "telem%u", &bidx); + if (sscanf((*a)->d_name, "telem%u", &aidx) != 1) + aidx = 0; + if (sscanf((*b)->d_name, "telem%u", &bidx) != 1) + bidx = 0; return (aidx > bidx) ? 1 : (aidx < bidx) ? -1 : 0; } |
