X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldif%2Ffetch.c;h=cb4d81beed8e93924a413b59713d6405f22bd660;hb=517900ec9bc4f9cf97d3194d5c613adc07dd6b51;hp=3f1ccf18a2430634b3b5a715e368ad52de5c2eb2;hpb=df8f7cbb9b79be3be9205d116d1dd0b263d6861a;p=openldap diff --git a/libraries/libldif/fetch.c b/libraries/libldif/fetch.c index 3f1ccf18a2..cb4d81beed 100644 --- a/libraries/libldif/fetch.c +++ b/libraries/libldif/fetch.c @@ -1,4 +1,9 @@ /* line64.c - routines for dealing with the slapd line format */ +/* $OpenLDAP$ */ +/* + * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ #include "portable.h" @@ -17,6 +22,7 @@ #include "ldap_log.h" #include "lber_pvt.h" #include "ldap_pvt.h" +#include "ldap_config.h" #include "ldif.h" int @@ -45,7 +51,8 @@ ldif_fetch_url( return -1; } - if( *p != *LDAP_DIRSEP ) { + /* we don't check for LDAP_DIRSEP since URLs should contain '/' */ + if( *p != '/' ) { /* skip over false root */ p++; } @@ -53,7 +60,7 @@ ldif_fetch_url( p = ber_strdup( p ); ldap_pvt_hex_unescape( p ); - url = fopen( p, "r" ); + url = fopen( p, "rb" ); } else { return -1; @@ -66,23 +73,32 @@ ldif_fetch_url( total = 0; - while( bytes = fread( buffer, 1, sizeof(buffer), url ) ) { - char *newp = ber_memrealloc( p, total + bytes ); + while( (bytes = fread( buffer, 1, sizeof(buffer), url )) != 0 ) { + char *newp = ber_memrealloc( p, total + bytes + 1 ); if( newp == NULL ) { ber_memfree( p ); fclose( url ); return -1; } - newp = p; - SAFEMEMCPY( &p[total], buffer, bytes ); + p = newp; + AC_MEMCPY( &p[total], buffer, bytes ); total += bytes; } 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; return 0; } -