From c67d38482d7c5ef7762e4fd3d44f7067d542bb45 Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 21 Mar 2021 10:43:06 +0100 Subject: [PATCH] add: Fix panic when history command returns nothing If you disable bash history files alltogether, "history 1" will not contain anything on first launch of a terminal and therefore the regex has nothing to parse, so we get an out of bounds array access. So fix this. Though it's a dirty silent fail now, I don't want error messages/warnings everytime I open a shell. --- main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 9abaac9..d9ee174 100644 --- a/main.go +++ b/main.go @@ -140,7 +140,9 @@ func main() { historycmd := args[1] var rgx = regexp.MustCompile("\\s+\\d+\\s+(.*)") rs := rgx.FindStringSubmatch(historycmd) - add(conn, rs[1]) + if len(rs) == 2 { + add(conn, rs[1]) + } } else if cmd == "search" { if argslen < 2 { fmt.Fprint(os.Stderr, "Please provide the search query\n")