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

zpool cmd: Fix buffer underflow if sysfs file is empty #16035

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

rrevans
Copy link
Contributor

@rrevans rrevans commented Mar 28, 2024

Motivation and Context

zpool_sysfs_gets will underflow if the sysfs file is empty

count = read(fd, buf, statbuf.st_size);
if (count < 0) {
/* Error doing read() or we overran the buffer */
close(fd);
free(buf);
return (NULL);
}
/* Remove trailing newline */
if (buf[count - 1] == '\n')
buf[count - 1] = 0;

Description

Test count > 0

How Has This Been Tested?

ZTS passes for all tests with tags matching zpool.*

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

Signed-off-by: Robert Evans <evansr@google.com>

Fixes: openzfs#16028
@tonyhutter tonyhutter added the Status: Accepted Ready to integrate (reviewed, tested) label Mar 28, 2024
@behlendorf behlendorf merged commit 2553f94 into openzfs:master Mar 29, 2024
13 of 15 checks passed
tonyhutter pushed a commit that referenced this pull request May 2, 2024
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Jason Lee <jasonlee@lanl.gov>
Signed-off-by: Robert Evans <evansr@google.com>
Closes #16028
Closes #16035
lundman pushed a commit to openzfsonwindows/openzfs that referenced this pull request Sep 4, 2024
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Jason Lee <jasonlee@lanl.gov>
Signed-off-by: Robert Evans <evansr@google.com>
Closes openzfs#16028
Closes openzfs#16035
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants