Skip to content

Commit

Permalink
Merge pull request #115 from lc/lc/fix-panic
Browse files Browse the repository at this point in the history
fix(panic): fix gau panic when output flag is provided
  • Loading branch information
lc authored Nov 2, 2023
2 parents abf8b12 + 4fa052d commit d556483
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 5 additions & 7 deletions cmd/gau/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,26 @@ func main() {

results := make(chan string)

var out io.Writer
var out = os.Stdout
// Handle results in background
if config.Output != "" {
out, err := os.OpenFile(config.Output, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
out, err = os.OpenFile(config.Output, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatalf("Could not open output file: %v\n", err)
}
defer out.Close()
} else {
out = os.Stdout
}

writeWg := new(sync.WaitGroup)
var writeWg sync.WaitGroup
writeWg.Add(1)
go func(JSON bool) {
go func(out io.Writer, JSON bool) {
defer writeWg.Done()
if JSON {
output.WriteURLsJSON(out, results, config.Blacklist, config.RemoveParameters)
} else if err = output.WriteURLs(out, results, config.Blacklist, config.RemoveParameters); err != nil {
log.Fatalf("error writing results: %v\n", err)
}
}(config.JSON)
}(out, config.JSON)

workChan := make(chan runner.Work)
gau.Start(workChan, results)
Expand Down
6 changes: 4 additions & 2 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ func WriteURLs(writer io.Writer, results <-chan string, blacklistMap mapset.Set[
if err != nil {
continue
}
if blacklistMap.Contains(strings.ToLower(path.Ext(u.Path))) {
if path.Ext(u.Path) != "" && blacklistMap.Contains(strings.ToLower(path.Ext(u.Path))) {
continue
}
if RemoveParameters && !lastURL.Add(u.Host+u.Path) {

if RemoveParameters && !lastURL.Contains(u.Host+u.Path) {
continue
}
lastURL.Add(u.Host + u.Path)

buf.B = append(buf.B, []byte(result)...)
buf.B = append(buf.B, "\n"...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/valyala/fasthttp"
)

const Version = `2.2.0`
const Version = `2.2.1`

// Provider is a generic interface for all archive fetchers
type Provider interface {
Expand Down

0 comments on commit d556483

Please sign in to comment.