Skip to content

Commit

Permalink
Merge branch 'main' into datatype_prediction
Browse files Browse the repository at this point in the history
  • Loading branch information
piyushroshan authored Nov 7, 2024
2 parents f72b47c + 5fbd62a commit acbd671
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
13 changes: 7 additions & 6 deletions internal/corazawaf/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,9 @@ func (tx *Transaction) GetField(rv ruleVariableParams) []experimentalTypes.Match
}

// in the most common scenario filteredMatches length will be
// the same as matches length, so we avoid allocating per result
filteredMatches := make([]experimentalTypes.MatchData, 0, len(matches))

// the same as matches length, so we avoid allocating per result.
// We reuse the matches slice to store filtered results avoiding extra allocation.
filteredCount := 0
for _, c := range matches {
isException := false
lkey := strings.ToLower(c.Key())
Expand All @@ -601,9 +601,11 @@ func (tx *Transaction) GetField(rv ruleVariableParams) []experimentalTypes.Match
}
}
if !isException {
filteredMatches = append(filteredMatches, c.(experimentalTypes.MatchData))
matches[filteredCount] = c
filteredCount++
}
}
matches = matches[:filteredCount]

if rv.Count {
count := len(filteredMatches)

Check failure on line 611 in internal/corazawaf/transaction.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

undefined: filteredMatches

Check failure on line 611 in internal/corazawaf/transaction.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

undefined: filteredMatches

Check failure on line 611 in internal/corazawaf/transaction.go

View workflow job for this annotation

GitHub Actions / lint

undefined: filteredMatches

Check failure on line 611 in internal/corazawaf/transaction.go

View workflow job for this annotation

GitHub Actions / lint

undefined: filteredMatches

Check failure on line 611 in internal/corazawaf/transaction.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, 0.33.0, ubuntu-latest)

undefined: filteredMatches

Check failure on line 611 in internal/corazawaf/transaction.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, 0.33.0, ubuntu-latest)

undefined: filteredMatches

Check failure on line 611 in internal/corazawaf/transaction.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, 0.33.0, ubuntu-latest)

undefined: filteredMatches

Check failure on line 611 in internal/corazawaf/transaction.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, 0.33.0, ubuntu-latest)

undefined: filteredMatches

Check failure on line 611 in internal/corazawaf/transaction.go

View workflow job for this annotation

GitHub Actions / test (1.23.x, ubuntu-latest)

undefined: filteredMatches

Check failure on line 611 in internal/corazawaf/transaction.go

View workflow job for this annotation

GitHub Actions / test (1.23.x, ubuntu-latest)

undefined: filteredMatches
Expand Down Expand Up @@ -1291,8 +1293,7 @@ func (tx *Transaction) ProcessResponseBody() (*types.Interruption, error) {
return tx.interruption, nil
}

// ProcessLogging Logging all information relative to this transaction.
// An error log
// ProcessLogging logs all information relative to this transaction.
// At this point there is not need to hold the connection, the response can be
// delivered prior to the execution of this method.
func (tx *Transaction) ProcessLogging() {
Expand Down
14 changes: 14 additions & 0 deletions internal/corazawaf/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,20 @@ func TestTxGetField(t *testing.T) {
}
}

func BenchmarkTxGetField(b *testing.B) {
tx := makeTransaction(b)
rvp := ruleVariableParams{
Variable: variables.Args,
}
for i := 0; i < b.N; i++ {
tx.GetField(rvp)
}
if err := tx.Close(); err != nil {
b.Fatalf("Failed to close transaction: %s", err.Error())
}
b.ReportAllocs()
}

func TestTxProcessURI(t *testing.T) {
waf := NewWAF()
tx := waf.NewTransaction()
Expand Down
3 changes: 0 additions & 3 deletions internal/seclang/directives.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,6 @@ func directiveSecAuditLogRelevantStatus(options *DirectiveOptions) error {
// Syntax: SecAuditLogParts [PARTLETTERS]
// Default: ABCFHZ
// ---
// The format of the audit log format is documented in detail in the Audit Log Data
// Format Documentation.
//
// Example:
// ```apache
// SecAuditLogParts ABCFHZ
Expand Down
1 change: 0 additions & 1 deletion types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ type Transaction interface {
ReadResponseBodyFrom(io.Reader) (*Interruption, int, error)

// ProcessLogging Logging all information relative to this transaction.
// An error log
// At this point there is not need to hold the connection, the response can be
// delivered prior to the execution of this method.
ProcessLogging()
Expand Down

0 comments on commit acbd671

Please sign in to comment.