X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fldif.c;h=f6c68407a0c17b390f95671938ccc563c217e093;hb=9b5972dc9e14e1f7a7bef755bfd0dc61bcf1ffb3;hp=9f868102ee7862925d19210082add8f9bee8b505;hpb=a26706d135b06f9c70a6ea90ddcff9c3a49f8c15;p=openldap diff --git a/libraries/libldap/ldif.c b/libraries/libldap/ldif.c index 9f868102ee..f6c68407a0 100644 --- a/libraries/libldap/ldif.c +++ b/libraries/libldap/ldif.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2014 The OpenLDAP Foundation. + * Copyright 1998-2016 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -819,7 +819,7 @@ ldif_read_record( char **bufp, /* ptr to malloced output buffer */ int *buflenp ) /* ptr to length of *bufp */ { - char line[LDIF_MAXLINE+2], *nbufp; + char line[LDIF_MAXLINE], *nbufp; ber_len_t lcur = 0, len; int last_ch = '\n', found_entry = 0, stop, top_comment = 0; @@ -838,20 +838,24 @@ ldif_read_record( break; } } - if ( stop ) - break; - - if ( fgets( line, sizeof( line ), lfp->fp ) == NULL ) { - stop = 1; - len = 0; - } else { - len = strlen( line ); + if ( !stop ) { + if ( fgets( line, sizeof( line ), lfp->fp ) == NULL ) { + stop = 1; + 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'; + if ( stop ) { + /* Add \n in case the file does not end with newline */ + if (last_ch != '\n') { + len = 1; + line[0] = '\n'; + line[1] = '\0'; + goto last; + } + break; } /* Squash \r\n to \n */ @@ -920,9 +924,10 @@ ldif_read_record( } } } - } + } } +last: if ( *buflenp - lcur <= len ) { *buflenp += len + LDIF_MAXLINE; nbufp = ber_memrealloc( *bufp, *buflenp );