Skip to content

Commit

Permalink
Check arguments length before reading
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 committed Jun 21, 2024
1 parent cbebc1e commit 4bc0a24
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func main() {
verbose := os.Getenv("VERBOSE") == "1"
padding := os.Getenv("PAD") == "1"
do := os.Getenv("DNSSEC") == "1"

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

subnetOpt := getSubnet()
ednsOpt := getEDNSOpt()
question := getQuestion()
Expand Down Expand Up @@ -66,12 +73,6 @@ func main() {
os.Exit(0)
}

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

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

0 comments on commit 4bc0a24

Please sign in to comment.