Skip to content

Commit

Permalink
Check arguments length before reading (#72)
Browse files Browse the repository at this point in the history
fix

```
panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
main.getQuestion()
        /build/dnslookup/parts/dnslookup/build/main.go:239 +0x147
main.main()
        /build/dnslookup/parts/dnslookup/build/main.go:44 +0x145
```
  • Loading branch information
Howard20181 authored Jun 23, 2024
1 parent cbebc1e commit 1540652
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func main() {
do := os.Getenv("DNSSEC") == "1"
subnetOpt := getSubnet()
ednsOpt := getEDNSOpt()
question := getQuestion()

if verbose {
log.SetLevel(log.DEBUG)
Expand All @@ -66,12 +65,14 @@ func main() {
os.Exit(0)
}

if len(os.Args) != 2 && len(os.Args) != 3 && len(os.Args) != 4 && len(os.Args) != 5 {
if len(os.Args) < 2 || len(os.Args) > 5 {
log.Printf("Wrong number of arguments")
usage()
os.Exit(1)
}

question := getQuestion()

if timeoutStr != "" {
i, err := strconv.Atoi(timeoutStr)
if err != nil {
Expand Down

0 comments on commit 1540652

Please sign in to comment.