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

Rui Zhang bbcallen at gmail.com
Sat Oct 13 16:52:42 CEST 2012


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>
 
 #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;
 
         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++;
+
+        /* 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" ) )
         {
-- 
1.7.10.4




More information about the vlc-devel mailing list