From 3f22535375a470ccb7e56663ac71823d1096ab00 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sat, 19 Jun 2021 18:44:00 -0400 Subject: [PATCH] Bug fix for -w flag usage If termshark is invoked like this: $ termshark -i eth0 -w foo.pcap then termshark will save the captured packets to foo.pcap. It checks to make sure that foo.pcap is not something that tshark will complain about, but I mistakenly did not bypass that check if foo.pcap does not exist, which will be the typical case. --- cmd/termshark/termshark.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index 748a9ce..c592b0f 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -450,9 +450,12 @@ func cmain() int { fmt.Fprintf(os.Stderr, "Cannot set -w to stdout. Target file must be regular or a symlink.\n") return 1 } - if !system.FileRegularOrLink(string(opts.WriteTo)) { - fmt.Fprintf(os.Stderr, "Cannot set -w to %s. Target file must be regular or a symlink.\n", opts.WriteTo) - return 1 + // If the file does not exist, then proceed. If it does exist, check it is something "normal". + if _, err = os.Stat(string(opts.WriteTo)); err == nil || !os.IsNotExist(err) { + if !system.FileRegularOrLink(string(opts.WriteTo)) { + fmt.Fprintf(os.Stderr, "Cannot set -w to %s. Target file must be regular or a symlink.\n", opts.WriteTo) + return 1 + } } }