Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

agent/rule/shellshock: fix splitting environment variables #153

Merged
merged 1 commit into from
Sep 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions internal/rule/callback/shellshock.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ func newShellshockPrologCallback(rule RuleFace, blockingMode bool, regexps []*re
}

for _, env := range env {
v := strings.Split(env, `=`)
if len(v) != 2 {
v := strings.SplitN(env, `=`, 2)
if l := len(v); l <= 0 || l > 2 {
ctx.Logger().Error(sqerrors.Errorf("unexpected number of elements split by `=` in `%s`", env))
return nil, nil
} else if l == 1 {
// Skip empty values
continue
}

name, value := v[0], v[1]
for _, re := range regexps {
if re.MatchString(value) {
Expand Down