]> git.sur5r.net Git - openldap/commitdiff
ITS#6947 Handle missing '\n' termination in LDIF input
authorJan Vcelak <jvcelak@redhat.com>
Mon, 20 Jun 2011 15:31:57 +0000 (17:31 +0200)
committerHoward Chu <hyc@openldap.org>
Tue, 21 Jun 2011 01:18:34 +0000 (18:18 -0700)
libraries/libldap/ldif.c

index 0ee7849f167cef03504764ee23630c30fb78393b..0bc35bb5a872407da0e77942b43b8fed4057fba9 100644 (file)
@@ -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)++;