Skip to content

CompileFilter crashes while logging error if the filter is missing brackets #117

@jjheinon

Description

@jjheinon

Example:

package main

import "github.com/go-ldap/ldap"

func main() {
	ldap.CompileFilter("((cn=)")
}

When running the example, it fails to parse the filter and crashes while logging the error message:

panic: runtime error: slice bounds out of range

goroutine 1 [running]:
panic(0x54ef60, 0xc82000a0e0)
	/usr/lib/golang/src/runtime/panic.go:481 +0x3e6
github.com/go-ldap/ldap.CompileFilter(0x57d790, 0x6, 0xc820014810, 0x0, 0x0)
	/root/src/github.com/go-ldap/ldap/filter.go:86 +0x41e
main.main()
	/root/test/test.go:6 +0x2c

The problem is with this line in ldap/filter.go, pos gets invalid value:

return nil, NewError(ErrorFilterCompile, errors.New("ldap: finished compiling filter with extra at end: "+fmt.Sprint(filter[pos:])))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions