Skip to content

Commit

Permalink
Bug fix for -w flag usage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gcla committed Jun 19, 2021
1 parent 5397b92 commit 3f22535
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cmd/termshark/termshark.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 3f22535

Please sign in to comment.