Skip to content

Commit

Permalink
Do not show static values
Browse files Browse the repository at this point in the history
change variable names
  • Loading branch information
rtpt-romankarwacik authored and rtpt-alexanderneumann committed Jan 26, 2024
1 parent 093db64 commit 60a6a6d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
20 changes: 10 additions & 10 deletions cmd/fuzz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,14 @@ func setupProducer(ctx context.Context, opts *Options) (*producer.Multiplexer, e
}

src := producer.NewRanges(ranges, opts.RangeFormat)
multiplexer.AddSource("FUZZ", src)
multiplexer.AddSource("FUZZ", src, true)

return multiplexer, nil

// handle old user interface, read from stdin
case opts.Filename == "-":
src := producer.NewFile(os.Stdin, false)
multiplexer.AddSource("FUZZ", src)
multiplexer.AddSource("FUZZ", src, true)

return multiplexer, nil

Expand All @@ -357,7 +357,7 @@ func setupProducer(ctx context.Context, opts *Options) (*producer.Multiplexer, e
}

src := producer.NewFile(file, true)
multiplexer.AddSource("FUZZ", src)
multiplexer.AddSource("FUZZ", src, true)

return multiplexer, nil
case len(opts.Values) > 0:
Expand All @@ -366,7 +366,7 @@ func setupProducer(ctx context.Context, opts *Options) (*producer.Multiplexer, e
inValues = append(inValues, []byte(v)...)
inValues = append(inValues, []byte("\n")...)
}
multiplexer.AddSource("FUZZ", producer.NewFile(bytes.NewReader(inValues), true))
multiplexer.AddSource("FUZZ", producer.NewFile(bytes.NewReader(inValues), true), true)
return multiplexer, nil
}

Expand All @@ -384,14 +384,14 @@ func setupProducer(ctx context.Context, opts *Options) (*producer.Multiplexer, e
switch r.Type {
case "file":
if r.Options == "-" {
multiplexer.AddSource(r.Name, producer.NewFile(os.Stdin, false))
multiplexer.AddSource(r.Name, producer.NewFile(os.Stdin, false), true)
} else {
f, err := os.Open(r.Options)
if err != nil {
return nil, fmt.Errorf("file source: %w", err)
}

multiplexer.AddSource(r.Name, producer.NewFile(f, true))
multiplexer.AddSource(r.Name, producer.NewFile(f, true), true)
}

case "range":
Expand Down Expand Up @@ -419,16 +419,16 @@ func setupProducer(ctx context.Context, opts *Options) (*producer.Multiplexer, e
}

src := producer.NewRanges(ranges, rangeFormat)
multiplexer.AddSource(r.Name, src)
multiplexer.AddSource(r.Name, src, true)
case "value":
multiplexer.AddSource(r.Name, producer.NewValue(r.Options))
multiplexer.AddSource(r.Name, producer.NewValue(r.Options), false)
case "exec":
err := producer.CheckExec(r.Options)
if err != nil {
return nil, fmt.Errorf("check replace %v: %w", r.Name, err)
}

multiplexer.AddSource(r.Name, producer.NewExec(r.Options))
multiplexer.AddSource(r.Name, producer.NewExec(r.Options), true)
default:
return nil, fmt.Errorf("unknown replace type %q", r.Type)
}
Expand Down Expand Up @@ -686,7 +686,7 @@ func run(ctx context.Context, g *errgroup.Group, opts *Options, args []string) e

// run the reporter
term.Printf(reporter.Bold("Target URL:")+" %v\n\n", targetURL)
reporter := reporter.New(term, opts.LongRequest, opts.IsTest)
reporter := reporter.New(term, opts.LongRequest, opts.IsTest, multiplexer.ShowValues)
err = reporter.Display(responseCh, countCh)

return err
Expand Down
8 changes: 5 additions & 3 deletions producer/multiplex.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

// Multiplexer takes several sources of values and returns the cross product.
type Multiplexer struct {
Names []string
Sources []Source
Names []string
Sources []Source
ShowValues []bool
}

type sourceCount struct {
Expand All @@ -18,9 +19,10 @@ type sourceCount struct {
}

// AddSource adds a source with the given name.
func (m *Multiplexer) AddSource(name string, src Source) {
func (m *Multiplexer) AddSource(name string, src Source, showValue bool) {
m.Names = append(m.Names, name)
m.Sources = append(m.Sources, src)
m.ShowValues = append(m.ShowValues, showValue)
}

// Run runs the multiplexer until ctx is cancelled. Both ch and count will be
Expand Down
16 changes: 14 additions & 2 deletions reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ type Reporter struct {
term cli.Terminal
longRequest time.Duration
printRequestAndResponse bool
showValues []bool
}

// New returns a new reporter. For requests which took longer than longRequest
// to process, the time is shown.
func New(term cli.Terminal, longRequest time.Duration, printRequestAndResponse bool) *Reporter {
return &Reporter{term: term, longRequest: longRequest, printRequestAndResponse: printRequestAndResponse}
func New(term cli.Terminal, longRequest time.Duration, printRequestAndResponse bool, showValues []bool) *Reporter {
return &Reporter{term: term, longRequest: longRequest, printRequestAndResponse: printRequestAndResponse, showValues: showValues}
}

// HTTPStats collects statistics about several HTTP responses.
Expand Down Expand Up @@ -113,6 +114,16 @@ func (h *HTTPStats) Report(last []string) (res []string) {
return res
}

func filterArray(toFilter []string, showValue []bool) []string {
var out []string
for i, v := range toFilter {
if showValue[i] {
out = append(out, v)
}
}
return out
}

// Display shows incoming Responses.
func (r *Reporter) Display(ch <-chan response.Response, countChannel <-chan int) error {
r.term.Printf(Bold("%7s %8s %8s %-8s %s\n"), "status", "header", "body", "value", "extract")
Expand All @@ -138,6 +149,7 @@ next_response:

select {
case resp, ok = <-ch:
resp.Values = filterArray(resp.Values, r.showValues)
if !ok {
break next_response
}
Expand Down
2 changes: 1 addition & 1 deletion reporter/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func FormatResponse(r response.Response, longRequest time.Duration) string {
var values string
if len(r.Values) == 1 {
values = fmt.Sprintf("%-8v", r.Values[0])
} else {
} else if len(r.Values) != 0 {
values = "[" + strings.Join(r.Values, ", ") + "]"
}

Expand Down

0 comments on commit 60a6a6d

Please sign in to comment.