rwinch / spring-ldap

Apache License 2.0
0 stars 0 forks source link

LDAP-233: LdifParser goes into infinite loop when passed a non-LDIF file #102

Closed rwinch closed 8 years ago

rwinch commented 13 years ago

Original Reporter: aliu Environment: Not Specified Version: 1.3.1 Migrated From: https://jira.spring.io//browse/LDAP-233 org.springframework.ldap.ldif.parser.LdifParser has a corner case in getRecord(), where an input file with no valid LDIF records will cause an infinite loop. This is because the main switch statement will always hit the default (do nothing) case, and the while loop does not have a condition to terminate at EOF.

This can be fixed by having the record variable initialized to null, and delaying creation of a new LdapAttributes object to inside of the switch's NewRecord case, and then adding a check at the end of the while loop for a null read result.

This allows us to differentiate between files where an LDIF entry is malformed vs cases where no entry was found at all. See attached for proposed fix.

An easy way to test this code is to feed an empty file into the parser.

rwinch commented 13 years ago

aliu said: Last version had a typo (returned false instead of null). Corrected in this version.

rwinch commented 11 years ago

marthursson said: Added test case and fixed according to patch suggestion.