openldap/openladp-segfault-ldif-nl-end.patch
2011-06-27 18:53:29 +02:00

32 lines
847 B
Diff

commit 83814a220fb70db8344469dc3e2db5357b36fc5c
Author: Jan Vcelak <jvcelak@redhat.com>
Date: Mon Jun 20 17:31:57 2011 +0200
ITS#6947 Handle missing '\n' termination in LDIF input
diff --git a/libraries/libldap/ldif.c b/libraries/libldap/ldif.c
index 0ee7849..0bc35bb 100644
--- a/libraries/libldap/ldif.c
+++ b/libraries/libldap/ldif.c
@@ -842,11 +842,16 @@ ldif_read_record(
if ( fgets( line, sizeof( line ), lfp->fp ) == NULL ) {
stop = 1;
- /* Add \n in case the file does not end with newline */
- line[0] = '\n';
- line[1] = '\0';
+ len = 0;
+ } else {
+ len = strlen( line );
+ }
+
+ if ( len == 0 || line[len-1] != '\n' ) {
+ /* Add \n in case the line/file does not end with newline */
+ line[len] = '\n';
+ line[++len] = '\0';
}
- len = strlen( line );
if ( last_ch == '\n' ) {
(*lno)++;