From 6cd8bb50a060eb27963db6bf0d37b4a8b56970ca Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Sun, 22 Dec 2024 17:05:56 +0100 Subject: [PATCH] fix: panic in `capture` command, when no arguments are passed --- internal/ebpf/probesfacade/captor/capture.go | 5 +++++ tests/integration.txtar | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/internal/ebpf/probesfacade/captor/capture.go b/internal/ebpf/probesfacade/captor/capture.go index a5e6723..c5327b2 100644 --- a/internal/ebpf/probesfacade/captor/capture.go +++ b/internal/ebpf/probesfacade/captor/capture.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/binary" + "errors" "fmt" "path/filepath" "sync" @@ -51,6 +52,10 @@ type ebpfSetup struct { // to the ebpf program. // Returns the ebpfSetup struct in case of seccess, an error in case of failure. func InitProbes(functionSymbol string, cmdArgs []string, opts CaptureOptions) (*ebpfSetup, error) { + if len(cmdArgs) == 0 { + return nil, errors.New("error no arguments provided, at least 1 argument is required") + } + if !opts.LibbpfOutput { // suppress libbpf log ouput bpf.SetLoggerCbs( diff --git a/tests/integration.txtar b/tests/integration.txtar index 5bf5a69..28777fa 100644 --- a/tests/integration.txtar +++ b/tests/integration.txtar @@ -35,6 +35,10 @@ exec harpoon capture -e -c -f main.main -- ./bin/example-app stderr 'command execution error: fork/exec .* permission denied' exec chmod +x bin/example-app +# test it doesn't panic when no arguments are provided +! exec harpoon capture -e -c -f main.main +stdout '.* error no arguments provided, at least 1 argument is required' + # setting up test application exists bin/example-app # this must be done within the testscript environment