Skip to content

Commit

Permalink
fix(gokrb5.config): do not panic on auth_to_local*
Browse files Browse the repository at this point in the history
Extended:
Also improve error reporting when we encounter incomplete parser
situations. Now, if we are in an unhandled parser situation, we will
return an explicit error instead of panicking on an IndexError.

Previous situation: passing an "auth_to_local" directive caused a Panic
when doing v := strings.TrimSpace(p[1])
  • Loading branch information
Matcha committed Sep 20, 2024
1 parent 855dbc7 commit 59bc3f9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config/krb5conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ func (r *Realm) parseLines(name string, lines []string) (err error) {
ignore = true
err = UnsupportedDirective{"v4 configurations are not supported"}
}
if strings.Contains(line, "auth_to_local") {
ignore = true
err = UnsupportedDirective{"auth_to_local* configurations are not supported"}
}
if strings.Contains(line, "{") {
c++
if ignore {
Expand All @@ -371,7 +375,11 @@ func (r *Realm) parseLines(name string, lines []string) (err error) {
continue
}
}
if !strings.Contains(line, "=") {
return InvalidErrorf(
"gokrb5.config.krb5conf.Realm.parseLines: abnormal parser situation, probably unsupported config directive for realm %s", r.Realm)

}
p := strings.Split(line, "=")
key := strings.TrimSpace(strings.ToLower(p[0]))
v := strings.TrimSpace(p[1])
Expand Down Expand Up @@ -476,6 +484,11 @@ func (d *DomainRealm) parseLines(lines []string) error {
if !strings.Contains(line, "=") {
return InvalidErrorf("realm line (%s)", line)
}
if !strings.Contains(line, "=") {
return InvalidErrorf(
"gokrb5.config.krb5conf.DomainRealm.parseLines: abnormal parser situation, probably unsupported config directive in DomainRealm section %s", strings.Join(lines, "\n"))

}
p := strings.Split(line, "=")
domain := strings.TrimSpace(strings.ToLower(p[0]))
realm := strings.TrimSpace(p[1])
Expand Down

0 comments on commit 59bc3f9

Please sign in to comment.