Skip to content

Resolve potential access beyond a metric buffer (from covscan report)#1907

Merged
natoscott merged 2 commits intohtop-dev:mainfrom
natoscott:covscan-dynamic-strings-pcp
Feb 19, 2026
Merged

Resolve potential access beyond a metric buffer (from covscan report)#1907
natoscott merged 2 commits intohtop-dev:mainfrom
natoscott:covscan-dynamic-strings-pcp

Conversation

@natoscott
Copy link
Member

No description provided.

@natoscott natoscott added bug 🐛 Something isn't working code quality ♻️ Code quality enhancement PCP PCP related issues labels Feb 19, 2026
Comment on lines 396 to 397
buffer[CLAMP(bytes, 0u, size - 1)] = '\0';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still needed, if the last thing is a delimiter and the subsequent metric evaluation failed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spot on - will fix up, thanks!

The PCP library provides a string safe routine to guarantee
string termination when sprintf-ing into a buffer.  Switch
to this as xSnprintf is designed to fail() rather than to
tolerate, which is more desirable behaviour when dealing
with user-supplied configuration files.

In order to prevent accidental use of xSnprintf in these
files in future, all snprintf-alike calls are switched to
the libpcp interface here.
If there is no space remaining in the meter buffer for
a suffix, just ignore it and continue on - it's better
to be safe in this rare corner case than risk a crash.
@natoscott natoscott added this to the 3.5.0 milestone Feb 19, 2026
@natoscott natoscott force-pushed the covscan-dynamic-strings-pcp branch from 975db66 to a8e0ce7 Compare February 19, 2026 22:00
@natoscott natoscott merged commit f8e7153 into htop-dev:main Feb 19, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐛 Something isn't working code quality ♻️ Code quality enhancement PCP PCP related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments