Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: throw if file has !digit characters #614

Closed
wants to merge 2 commits into from

Conversation

rexagod
Copy link
Contributor

@rexagod rexagod commented Mar 19, 2024

Throw if file has non-numeric data, in addition to hinting the path that caused the error.

Fixes: #304, prometheus/node_exporter#1710

Throw if file has non-numeric data, in addition to hinting the path that
caused the error.

Fixes: prometheus#304, prometheus/node_exporter#1710
Signed-off-by: Pranshu Srivastava <[email protected]>
@discordianfish
Copy link
Member

See ci errors

Copy link
Member

@discordianfish discordianfish left a comment

Choose a reason for hiding this comment

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

LGTM

if string(c) == "\n" {
continue
}
if !unicode.IsDigit(rune(c)) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this is going to match a whole bunch of unicode glyph runes that are not [0-9]. I think we should be more strict and check like this:

Suggested change
if !unicode.IsDigit(rune(c)) {
if !strings.ContainsAny(c, "0123456789") {

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

Actually, looking at the upstream issue, we already see that this function is returning strconv.ErrSyntax from strconv.ParseUint(). I think the issue is the node_exporter is just not ignoring this specific error.

I don't think we need to make this change as the upstream strconv.ParseUint() is already doing a rune check on the string.

@SuperQ SuperQ closed this Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle cpufreq files with <unknown> values.
3 participants