From 65e163d2686193e32088c7850daa13f34d36bd0b Mon Sep 17 00:00:00 2001 From: Jan Vcelak Date: Mon, 20 Jun 2011 17:31:57 +0200 Subject: [PATCH] ITS#6947 Handle missing '\n' termination in LDIF input --- libraries/libldap/ldif.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libraries/libldap/ldif.c b/libraries/libldap/ldif.c index 0ee7849f16..0bc35bb5a8 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)++; -- 2.39.5