Le decadi 20 ventôse, an CCXXIII, Nicolas George a écrit :
> I will try to propose another patch for pure validation.

See the attached patches.

Regards,

-- 
  Nicolas George
From cef95aaec223b6644db6e52f9c6452d7aa01648b Mon Sep 17 00:00:00 2001
From: Nicolas George <geo...@nsup.org>
Date: Tue, 10 Mar 2015 13:43:17 +0100
Subject: [PATCH 1/2] lavf/http: full validation of headers option string.

Signed-off-by: Nicolas George <geo...@nsup.org>
---
 libavformat/http.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 52 insertions(+), 6 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index 55dcb6e..2d8f5dc 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -25,6 +25,7 @@
 #include <zlib.h>
 #endif /* CONFIG_ZLIB */
 
+#include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
 #include "libavutil/opt.h"
 
@@ -292,6 +293,55 @@ int ff_http_averror(int status_code, int default_averror)
         return default_averror;
 }
 
+static void validate_headers_option(void *log, unsigned char *header)
+{
+    unsigned char *p = header;
+    const char *error = NULL;
+    int tag;
+
+    /* *( header-field CRLF ) */
+    while (*p) {
+        /* header-field = field-name ":" OWS field-value OWS
+           field-name = token = 1*tchar */
+        tag = 0;
+        while ((unsigned)((*p | 32) - 'a') < 26 || (unsigned)(*p - '0') < 10 ||
+               *p == '!' || *p == '#' || *p == '$' || *p == '%' || *p == '&' ||
+               *p =='\'' || *p == '*' || *p == '+' || *p == '-' || *p == '.' ||
+               *p == '^' || *p == '_' || *p == '`' || *p == '|' || *p == '~') {
+            p++;
+            tag = 1;
+        }
+        if (!tag || *p != ':') {
+            error = "no valid field name";
+            goto fail;
+        }
+        /* field-value = *( field-content / obs-fold )
+           field-content  = field-vchar [ 1*( SP / HTAB ) field-vchar ]
+           field-vchar = VCHAR / obs-text
+           VCHAR = visible USASCII character
+           obs-text = %x80-FF
+           obs-fold = CRLF 1*( SP / HTAB ) */
+        while (*p) {
+            while (*p >= 32 || *p == '\t')
+                p++;
+            if (p[0] != '\r' || p[1] != '\n') {
+                error = *p ? "invalid character in vield value" :
+                             "missing trailing CRLF";
+                goto fail;
+            }
+            p += 2;
+            if (*p != ' ' && *p != '\t')
+                break;
+            p++;
+        }
+    }
+    return;
+
+fail:
+    av_log(log, AV_LOG_WARNING, "Invalid HTTP header at offset %u: %s\n",
+           (unsigned)(p - header), error);
+}
+
 static int http_open(URLContext *h, const char *uri, int flags,
                      AVDictionary **options)
 {
@@ -310,12 +360,8 @@ static int http_open(URLContext *h, const char *uri, int flags,
     if (options)
         av_dict_copy(&s->chained_options, *options, 0);
 
-    if (s->headers) {
-        int len = strlen(s->headers);
-        if (len < 2 || strcmp("\r\n", s->headers + len - 2))
-            av_log(h, AV_LOG_WARNING,
-                   "No trailing CRLF found in HTTP header.\n");
-    }
+    if (s->headers)
+        validate_headers_option(s, s->headers);
 
     ret = http_open_cnx(h, options);
     if (ret < 0)
-- 
2.1.4

From 68591d1dc097cae158eb8bcb08abc884dc414a3d Mon Sep 17 00:00:00 2001
From: Nicolas George <geo...@nsup.org>
Date: Wed, 11 Mar 2015 11:50:21 +0100
Subject: [PATCH 2/2] doc/protocols: insist on HTTP headers syntax.

Signed-off-by: Nicolas George <geo...@nsup.org>
---
 doc/protocols.texi | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index 5f6dfa8..b46a36d 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -230,7 +230,8 @@ Set a specific content type for the POST messages.
 
 @item headers
 Set custom HTTP headers, can override built in default headers. The
-value must be a string encoding the headers.
+value must be a string encoding the headers, with lines terminated by CRLF,
+including the final one.
 
 @item multiple_requests
 Use persistent connections if set to 1, default is 0.
-- 
2.1.4

Attachment: signature.asc
Description: Digital signature

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

Reply via email to