Skip to content

Commit

Permalink
collector/zfs: Prevent procfs integer underflow
Browse files Browse the repository at this point in the history
Prevent integer underflow when parsing the `procfs` file as it used a
`ParseUint` to parse signed values.

Fixes: prometheus#2766
Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
  • Loading branch information
rexagod committed Mar 18, 2024
1 parent 32ac7f4 commit f8be6ce
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions collector/zfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,21 @@ func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmtExt string, handler

// kstat data type (column 2) should be KSTAT_DATA_UINT64, otherwise ignore
// TODO: when other KSTAT_DATA_* types arrive, much of this will need to be restructured
if parts[1] == kstatDataUint64 || parts[1] == kstatDataInt64 {
key := fmt.Sprintf("kstat.zfs.misc.%s.%s", fmtExt, parts[0])
key := fmt.Sprintf("kstat.zfs.misc.%s.%s", fmtExt, parts[0])
switch parts[1] {
case kstatDataUint64:
value, err := strconv.ParseUint(parts[2], 10, 64)
if err != nil {
return fmt.Errorf("could not parse expected integer value for %q", key)
}
// Handle unsigned integer value.
handler(zfsSysctl(key), value)
case kstatDataInt64:
value, err := strconv.ParseInt(parts[2], 10, 64)
if err != nil {
return fmt.Errorf("could not parse expected integer value for %q", key)
}
// Handle signed integer value.
handler(zfsSysctl(key), value)

Check failure on line 181 in collector/zfs_linux.go

View workflow job for this annotation

GitHub Actions / lint

cannot use value (variable of type int64) as uint64 value in argument to handler) (typecheck)

Check failure on line 181 in collector/zfs_linux.go

View workflow job for this annotation

GitHub Actions / lint

cannot use value (variable of type int64) as uint64 value in argument to handler (typecheck)
}
}
Expand Down

0 comments on commit f8be6ce

Please sign in to comment.