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

pkg/ls:FromOSFileInfo: fix a panic if fi.Sys() returns the wrong type #2723

Merged
merged 2 commits into from
Jul 22, 2023

Conversation

rminnich
Copy link
Member

@rminnich rminnich commented Jul 21, 2023

FromOSFileInfo had a blind cast of a FileInfo.Sys() to *syscall.Stat_t.

This could fail with a badly behaving file system, e.g. a 9p server that would fail a Stat in ways that the go runtime was not prepared for. Ask me how I know :-) The fact that we have not seen this in 11 years of use testifies to its rarity, but ... it can happen.

In FromOSFileInfo, pick default values for UID, GID, and rdev

Check if fi.Sys() is a *syscall.Stat_t and, if so, use Uid, Gid, and Rdev from it.

Add a type to the linux test that implements os.FileInfo (yes, fs.FileInfo now ...) that can return a Sys() of the wrong type. I verified that this test
catches the failing case.

A bit of cleanup:
Rename the test file ls_linux_test.go to fileinfo_linux_test.go, to match everything else in this directory.

Remove a spurious fmt.Printf from the fileinfo_linux_test.go that added trash to the test output.

FromOSFileInfo had a blind cast of a FileInfo.Sys() to *syscall.Stat_t.

This could fail with a badly behaving file system, e.g. a
9p server that would fail a Stat in ways that the go runtime
was not prepared for.  Ask me how I know :-) The fact
that we have not seen this in 11 years of use testifies
to its rarity, but ... it can happen.

In FromOSFileInfo, pick default values for UID, GID, and rdev

Check if fi.Sys() is a *syscall.Stat_t and, if so, use
Uid, Gid, and Rdev from it.

Add a type to the linux test that implements os.FileInfo
(yes, fs.FileInfo now ...) that can return a Sys()
of the wrong type. I verified that this test
catches the failing case.

A bit of cleanup:
Rename the test file ls_linux_test.go to fileinfo_linux_test.go,
to match everything else in this directory.

Remove a spurious fmt.Printf from the fileinfo_linux_test.go
that added trash to the test output.

Signed-off-by: Ronald G Minnich <rminnich@gmail.com>
This came was introduced as a result of trying to match how "normal"
ls works.

Sorry about that.

Signed-off-by: Ronald G Minnich <rminnich@gmail.com>
@codecov
Copy link

codecov bot commented Jul 21, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.03 ⚠️

Comparison is base (69f0fdd) 75.41% compared to head (dee5cc2) 75.39%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2723      +/-   ##
==========================================
- Coverage   75.41%   75.39%   -0.03%     
==========================================
  Files         414      414              
  Lines       42229    42231       +2     
==========================================
- Hits        31847    31838       -9     
- Misses      10382    10393      +11     
Impacted Files Coverage Δ
cmds/core/ls/ls.go 88.15% <100.00%> (ø)
pkg/ls/fileinfo_unix.go 88.88% <100.00%> (+0.36%) ⬆️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rminnich rminnich requested a review from brho July 21, 2023 23:52
@rminnich rminnich merged commit b816797 into u-root:main Jul 22, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting reviewer Waiting for a reviewer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants