[vlc-commits] https: discard leading and trailing OWS in header field values

Rémi Denis-Courmont git at videolan.org
Tue Dec 22 23:34:13 CET 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Dec 23 00:32:31 2015 +0200| [eeab18ae0547bd91b316466c185fd47bf30c1577] | committer: Rémi Denis-Courmont

https: discard leading and trailing OWS in header field values

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=eeab18ae0547bd91b316466c185fd47bf30c1577
---

 modules/access/http/message.c |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/modules/access/http/message.c b/modules/access/http/message.c
index c2f61c0..d6ba97d 100644
--- a/modules/access/http/message.c
+++ b/modules/access/http/message.c
@@ -68,7 +68,8 @@ static int vlc_http_msg_vadd_header(struct vlc_http_msg *m, const char *name,
     }
 
     char *value;
-    if (unlikely(vasprintf(&value, fmt, ap) < 0))
+    int len = vasprintf(&value, fmt, ap);
+    if (unlikely(len < 0))
         return -1;
 
     /* IETF RFC7230 §3.2.4 */
@@ -76,6 +77,19 @@ static int vlc_http_msg_vadd_header(struct vlc_http_msg *m, const char *name,
         if (*p == '\r' || *p == '\n')
             *p = ' ';
 
+    /* Discard leading OWS */
+    size_t crop = strspn(value, "\t ");
+    if (crop > 0)
+    {
+        assert((unsigned)len >= crop);
+        memmove(value, value + crop, len - crop + 1);
+        len -= crop;
+    }
+
+    /* Discard trailing OWS */
+    while (len > 0 && (value[len - 1] == '\t' || value[len - 1] == ' '))
+        value[--len] = '\0';
+
     /* Fold identically named header field values. This is unfortunately not
      * possible for Set-Cookie, while Cookie requires a special separator. */
     ssize_t idx = vlc_http_msg_find_header(m, name);



More information about the vlc-commits mailing list