Skip to content

Commit

Permalink
fix: panic in capture command, when no arguments are passed
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini authored and alegrey91 committed Dec 24, 2024
1 parent 2f95714 commit 6cd8bb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/ebpf/probesfacade/captor/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/binary"
"errors"
"fmt"
"path/filepath"
"sync"
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions tests/integration.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6cd8bb5

Please sign in to comment.