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

Fix crash when file is nil #1698

Merged
merged 1 commit into from
May 6, 2024
Merged

Fix crash when file is nil #1698

merged 1 commit into from
May 6, 2024

Conversation

ormai
Copy link
Contributor

@ormai ormai commented Apr 26, 2024

Lf crashes when the cursor is on openpgp-revocs.d with

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x59663c]

goroutine 6 [running]:
main.getFileExtension({0x0, 0x0})
	github.com/gokcehan/lf/misc.go:306 +0x1c
main.readdir({0xc0002f0810, 0x2f})
	github.com/gokcehan/lf/nav.go:91 +0x325
main.newDir({0xc0002f0810, 0x2f})
	github.com/gokcehan/lf/nav.go:183 +0x53
main.(*nav).loadDirInternal.func1()
	github.com/gokcehan/lf/nav.go:484 +0x25
created by main.(*nav).loadDirInternal in goroutine 1
	github.com/gokcehan/lf/nav.go:483 +0x1fa

file gets dereferenced in getFileExtension even though it's nil.

Copy link
Collaborator

@joelim-work joelim-work left a comment

Choose a reason for hiding this comment

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

Thanks for the bug report and patch.

The patch should work, but maybe as a minor suggestion it might be better to avoid using the FileInfo object at all (i.e. passing it to getFileExtension) if the stat call fails.

Something like this:

diff --git a/nav.go b/nav.go
index dc95498..9937f5a 100644
--- a/nav.go
+++ b/nav.go
@@ -88,7 +88,7 @@ func readdir(path string) ([]*file, error) {
 				dirSize:    -1,
 				accessTime: time.Unix(0, 0),
 				changeTime: time.Unix(0, 0),
-				ext:        getFileExtension(lstat),
+				ext:        "",
 				err:        err,
 			})
 			continue

@ormai
Copy link
Contributor Author

ormai commented Apr 27, 2024

@joelim-work Of course removing a function call is better than adding a check for nil.

Copy link
Collaborator

@joelim-work joelim-work left a comment

Choose a reason for hiding this comment

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

Cool, thanks once again for the changes 👍

@joelim-work
Copy link
Collaborator

I think this can be merged, it's a small change and would prevent crashes from happening otherwise.

@joelim-work joelim-work merged commit a6375d5 into gokcehan:master May 6, 2024
4 checks passed
@joelim-work
Copy link
Collaborator

Just leaving a minor note that this change doesn't need to be listed in the release notes, since it was caused by a bug in #1670, which was added after version r32.

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.

2 participants