Skip to content

Commit 78124a0

Browse files
dkorunicmjuraga
authored andcommitted
BUG/MEDIUM: configuration: fix crashes and non-idempotent serialization
1 parent be07977 commit 78124a0

29 files changed

Lines changed: 157 additions & 35 deletions

.aspell.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,14 @@ allowed:
233233
- rehaul
234234
- rebase
235235
- XXXX
236+
- bufio
237+
- dereferences
238+
- gosentry
239+
- libafl
240+
- reparse
241+
- reparsing
242+
- tokenization
243+
- untrusted
244+
- allowlist
245+
- gocognit
246+
- nolint

config-parser/parsers/acl.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ func (h *ACL) Result() ([]common.ReturnResultLine, error) {
5656
sb.WriteString(req.ACLName)
5757
sb.WriteString(" ")
5858
sb.WriteString(req.Criterion)
59-
sb.WriteString(" ")
60-
sb.WriteString(req.Value)
59+
if req.Value != "" {
60+
sb.WriteString(" ")
61+
sb.WriteString(req.Value)
62+
}
6163

6264
comment, err := misc.SerializeMetadata(req.Metadata)
6365
if err != nil {

config-parser/parsers/actions/check-set-var-fmt.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ func (f *SetVarFmtCheck) Parse(parts []string, parserType types.ParserType, comm
5050
data = strings.TrimPrefix(data, "set-var-fmt(")
5151
data = strings.TrimRight(data, ")")
5252
d := strings.SplitN(data, ".", 2)
53+
if len(d) < 2 {
54+
return stderrors.New("not enough params")
55+
}
5356
f.VarScope = d[0]
5457
f.VarName = d[1]
5558
command, condition := common.SplitRequest(command)

config-parser/parsers/actions/do-resolve.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ func (f *DoResolve) Parse(parts []string, parserType types.ParserType, comment s
5454
}
5555
data = strings.TrimPrefix(data, "do-resolve(")
5656
data = strings.TrimRight(data, ")")
57+
if strings.ContainsAny(data, "\"'") {
58+
// An unbalanced quote swallowed following tokens into the name; the
59+
// result can't round-trip and grows by ") " on every save.
60+
return stderrors.New("not enough params")
61+
}
5762
d := strings.SplitN(data, ",", 3)
5863

5964
if len(d) < 2 {

config-parser/parsers/actions/sc-set-gpt.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func (f *ScSetGpt) Parse(parts []string, parserType types.ParserType, comment st
5858
// sc-get-gpt(sc-id,idx)
5959
start := len("sc-set-gpt(")
6060
end := len(data) - 1 // ignore ")"
61+
if end < start {
62+
// e.g. a truncated "sc-set-gpt(" with no "<sc-id>,<idx>)" body.
63+
return stderrors.New("missing sc-id and/or idx")
64+
}
6165
idIdx := strings.Split(data[start:end], ",")
6266
if len(idIdx) != 2 {
6367
return stderrors.New("missing sc-id and/or idx")

config-parser/parsers/actions/sc_add_gpc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ func (f *ScAddGpc) Parse(parts []string, parserType types.ParserType, comment st
5656
idIdx := strings.TrimPrefix(data, "sc-add-gpc(")
5757
idIdx = strings.TrimRight(idIdx, ")")
5858
idIdxValues := strings.SplitN(idIdx, ",", 2)
59+
if len(idIdxValues) < 2 {
60+
return stderrors.New("not enough params")
61+
}
5962
f.Idx, f.ID = idIdxValues[0], idIdxValues[1]
6063
if len(parts) < minLen {
6164
return stderrors.New("not enough params")

config-parser/parsers/actions/sc_inc_gpc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func (f *ScIncGpc) Parse(parts []string, parserType types.ParserType, comment st
5454
idIdx := strings.TrimPrefix(data, "sc-inc-gpc(")
5555
idIdx = strings.TrimRight(idIdx, ")")
5656
idIdxValues := strings.SplitN(idIdx, ",", 2)
57+
if len(idIdxValues) < 2 {
58+
return stderrors.New("not enough params")
59+
}
5760
f.Idx, f.ID = idIdxValues[0], idIdxValues[1]
5861
if len(parts) == minLen {
5962
return nil

config-parser/parsers/actions/set-bandwidth-limit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func (f *SetBandwidthLimit) Parse(parts []string, parserType types.ParserType, c
5353
command = parts[3:]
5454
}
5555
command, condition := common.SplitRequest(command)
56+
if len(command) == 0 {
57+
return stderrors.New("not enough params")
58+
}
5659
f.Name = command[0]
5760

5861
for i := 1; i < len(command); i++ {

config-parser/parsers/actions/set-var-check.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ func (f *SetVarCheck) Parse(parts []string, parserType types.ParserType, comment
5050
data = strings.TrimPrefix(data, "set-var(")
5151
data = strings.TrimRight(data, ")")
5252
d := strings.SplitN(data, ".", 2)
53+
if len(d) < 2 {
54+
return stderrors.New("not enough params")
55+
}
5356
f.VarScope = d[0]
5457
f.VarName = d[1]
5558
command, condition := common.SplitRequest(command)

config-parser/parsers/actions/set-var-fmt.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,15 @@ func (f *SetVarFmt) Parse(parts []string, parserType types.ParserType, comment s
5454
}
5555
data = strings.TrimPrefix(data, "set-var-fmt(")
5656
data = strings.TrimRight(data, ")")
57+
if strings.ContainsAny(data, "\"'") {
58+
// An unbalanced quote swallowed following tokens into the name; the
59+
// result can't round-trip and grows by ") " on every save.
60+
return stderrors.New("not enough params")
61+
}
5762
d := strings.SplitN(data, ".", 2)
63+
if len(d) < 2 {
64+
return stderrors.New("not enough params")
65+
}
5866
f.VarScope = d[0]
5967
f.VarName = d[1]
6068
command, condition := common.SplitRequest(command)

0 commit comments

Comments
 (0)