junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
61.81k stars 2.35k forks source link

Panic when killing script since 83b6033 'main.go' #3863

Closed LangLangBart closed 2 weeks ago

LangLangBart commented 2 weeks ago

Checklist

Output of fzf --version

0.53.0 (brew)

OS

Shell

Problem / Steps to reproduce

Since commit 83b603390683d49ff75b72d142b4dba4b5186d73 (main.go), I noticed a panic when killing a script, where fzf runs.

--- a/main.go
+++ b/main.go
@@ -36,5 +36,5 @@ func printScript(label string, content []byte) {

 func exit(code int, err error) {
- if err != nil {
+ if code == fzf.ExitError {
    fmt.Fprintln(os.Stderr, err.Error())
  }

to reproduce

Run this small script in a terminal tab; the $$ is copied to your clipboard (macOS only).

#!/usr/bin/env bash

echo $$ | pbcopy
: | FZF_DEFAULT_OPTS="" fzf

In a second terminal tab, run the following:

kill -15 <copied_pid>

Examine the first terminal tab and notice the panic.

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

            goroutine 1 [running]:
                                  main.exit(0x2, {0x0?, 0x0?})
                                                                github.com/junegunn/fzf/main.go:39 +0x23
                                                                                                        main.main()
                                                                                                                        github.com/junegunn/fzf/main.go:81 +0x198

possible solution

Maybe check for nil or have a dedicated message for nil?

if code == fzf.ExitError && err != nil
junegunn commented 2 weeks ago

Thanks, nice find.