[vlc-devel] [PATCH] http: trim trailing space in field content

Rémi Denis-Courmont remi at remlab.net
Sat Oct 13 17:48:09 CEST 2012


Comments inline...

Le samedi 13 octobre 2012 17:52:42, Rui Zhang a écrit :
> With trailing space, header like "Location: http://host/path "
> could redirect to wrong Url.
> ---
>  modules/access/http.c |   18 ++++++++++++++++--
>  1 个文件被修改,插入 16 行(+),删除 2 行(-)
> 
> diff --git a/modules/access/http.c b/modules/access/http.c
> index cd388cc..05e86bc 100644
> --- a/modules/access/http.c
> +++ b/modules/access/http.c
> @@ -54,6 +54,7 @@
> 
>  #include <assert.h>
>  #include <limits.h>
> +#include <ctype.h>

Hmm, no. is*() functions are locale-dependent. HTTP is not locale-dependent. 

> 
>  #ifdef HAVE_LIBPROXY
>  #    include <proxy.h>
> @@ -1380,7 +1381,8 @@ static int Request( access_t *p_access, uint64_t
> i_tell ) for( ;; )
>      {
>          char *psz = net_Gets( p_access, p_sys->fd, pvs );
> -        char *p;
> +        char *p = NULL;
> +        char *p_trailing = NULL;

I don't see why you need to initialize the variables here.

> 
>          if( psz == NULL )
>          {
> @@ -1408,7 +1410,19 @@ static int Request( access_t *p_access, uint64_t
> i_tell ) goto error;
>          }
>          *p++ = '\0';
> -        while( *p == ' ' ) p++;
> +        while( isspace( *p ) ) p++;

Use strspn() instead. It does not depend on the locale.

> +
> +        /* trim trailing white space */
> +        p_trailing = p + strlen( p );
> +        if( p_trailing > p )
> +        {
> +            p_trailing--;
> +            while( isspace( *p_trailing ) && p_trailing > p )
> +            {
> +                *p_trailing = '\0';
> +                p_trailing--;
> +            }
> +        }
> 
>          if( !strcasecmp( psz, "Content-Length" ) )
>          {

-- 
Rémi Denis-Courmont
http://www.remlab.net/



More information about the vlc-devel mailing list