From f0cf58a8d9fddd9feaa65d15adf918417d275b22 Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Tue, 7 Aug 2007 17:18:34 +0000 Subject: [PATCH] Fix HTTP authentication. Yes, some sites use empty usernames --- modules/access/http.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/modules/access/http.c b/modules/access/http.c index bff3974805..1bc22c7722 100644 --- a/modules/access/http.c +++ b/modules/access/http.c @@ -932,37 +932,41 @@ static int Request( access_t *p_access, int64_t i_tell ) } /* Authentication */ - if( p_sys->url.psz_username && *p_sys->url.psz_username ) + if( p_sys->url.psz_username || p_sys->url.psz_password ) { - char *buf; + char buf[strlen( p_sys->url.psz_username ?: "" ) + + strlen( p_sys->url.psz_password ?: "" ) + 2]; char *b64; - asprintf( &buf, "%s:%s", p_sys->url.psz_username, - p_sys->url.psz_password ? p_sys->url.psz_password : "" ); - + snprintf( buf, sizeof( buf ), "%s:%s", p_sys->url.psz_username ?: "", + p_sys->url.psz_password ?: "" ); b64 = vlc_b64_encode( buf ); - free( buf ); - net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, - "Authorization: Basic %s\r\n", b64 ); - free( b64 ); + if( b64 != NULL ) + { + net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, + "Authorization: Basic %s\r\n", b64 ); + free( b64 ); + } } /* Proxy Authentication */ - if( p_sys->proxy.psz_username && *p_sys->proxy.psz_username ) + if( p_sys->proxy.psz_username || p_sys->proxy.psz_password ) { - char *buf; + char buf[strlen( p_sys->proxy.psz_username ?: "" ) + + strlen( p_sys->proxy.psz_password ?: "" )]; char *b64; - asprintf( &buf, "%s:%s", p_sys->proxy.psz_username, - p_sys->proxy.psz_password ? p_sys->proxy.psz_password : "" ); - + snprintf( buf, sizeof( buf ), "%s:%s", p_sys->proxy.psz_username ?: "", + p_sys->proxy.psz_password ?: "" ); b64 = vlc_b64_encode( buf ); - free( buf ); - net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, - "Proxy-Authorization: Basic %s\r\n", b64 ); - free( b64 ); + if( b64 != NULL) + { + net_Printf( VLC_OBJECT(p_access), p_sys->fd, pvs, + "Proxy-Authorization: Basic %s\r\n", b64 ); + free( b64 ); + } } /* ICY meta data request */ -- 2.39.2