X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldif%2Ffetch.c;h=cb4d81beed8e93924a413b59713d6405f22bd660;hb=517900ec9bc4f9cf97d3194d5c613adc07dd6b51;hp=3038676501e40649988653555502751ac1b8855e;hpb=e6d6faf3c9a2089b621804501c39dcb14e402b23;p=openldap diff --git a/libraries/libldif/fetch.c b/libraries/libldif/fetch.c index 3038676501..cb4d81beed 100644 --- a/libraries/libldif/fetch.c +++ b/libraries/libldif/fetch.c @@ -1,7 +1,7 @@ /* line64.c - routines for dealing with the slapd line format */ /* $OpenLDAP$ */ /* - * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. + * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ @@ -74,7 +74,7 @@ ldif_fetch_url( total = 0; while( (bytes = fread( buffer, 1, sizeof(buffer), url )) != 0 ) { - char *newp = ber_memrealloc( p, total + bytes ); + char *newp = ber_memrealloc( p, total + bytes + 1 ); if( newp == NULL ) { ber_memfree( p ); fclose( url ); @@ -87,6 +87,16 @@ ldif_fetch_url( fclose( url ); + if( total == 0 ) { + char *newp = ber_memrealloc( p, 1 ); + if( newp == NULL ) { + ber_memfree( p ); + return -1; + } + p = newp; + } + + p[total] = '\0'; *valuep = p; *vlenp = total;