mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
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 actively seen by users.
Fixes: 4265a86582 ("tools/power turbostat: Add PMT directory iterator helper")
Assisted-by: Claude:claude-sonnet-4.6
Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
parent
e1708e514a
commit
e817a533bb
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user