-
Notifications
You must be signed in to change notification settings - Fork 319
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
Conversation
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]>
See ci errors |
Signed-off-by: Pranshu Srivastava <[email protected]>
There was a problem hiding this 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)) { |
There was a problem hiding this comment.
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:
if !unicode.IsDigit(rune(c)) { | |
if !strings.ContainsAny(c, "0123456789") { |
There was a problem hiding this 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.
Throw if file has non-numeric data, in addition to hinting the path that caused the error.
Fixes: #304, prometheus/node_exporter#1710