avformat/hls: More strict url checks
authorMichael Niedermayer <michael@niedermayer.cc>
Fri, 15 Jan 2016 12:29:38 +0000 (13:29 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Fri, 15 Jan 2016 16:23:55 +0000 (17:23 +0100)
No case is known where these are needed

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 6ba42b6482c725a59eb468391544dc0c75b8c6f0)

Conflicts:

libavformat/hls.c

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Conflicts:

libavformat/hls.c

libavformat/hls.c

index 96bcb36..6c3424b 100644 (file)
@@ -911,6 +911,19 @@ static void update_options(char **dest, const char *name, void *src)
         av_freep(dest);
 }
 
+static int check_url(const char *url) {
+    const char *proto_name = avio_find_protocol_name(url);
+    if (!av_strstart(proto_name, "http", NULL) && !av_strstart(proto_name, "file", NULL))
+        return AVERROR_INVALIDDATA;
+
+    if (!strncmp(proto_name, url, strlen(proto_name)) && url[strlen(proto_name)] == ':')
+        return 0;
+    else if (strcmp(proto_name, "file") || !strcmp(url, "file,"))
+        return AVERROR_INVALIDDATA;
+
+    return 0;
+}
+
 static int open_input(HLSContext *c, struct playlist *pls)
 {
     AVDictionary *opts = NULL;
@@ -938,11 +951,9 @@ static int open_input(HLSContext *c, struct playlist *pls)
            seg->url, seg->url_offset, pls->index);
 
     if (seg->key_type == KEY_NONE) {
-        const char *proto_name = avio_find_protocol_name(seg->url);
-        if (!av_strstart(proto_name, "http", NULL) && !av_strstart(proto_name, "file", NULL)) {
-            ret = AVERROR_INVALIDDATA;
+        ret = check_url(seg->url);
+        if (ret < 0)
             goto cleanup;
-        }
 
         ret = ffurl_open(&pls->input, seg->url, AVIO_FLAG_READ,
                           &pls->parent->interrupt_callback, &opts);
@@ -951,11 +962,10 @@ static int open_input(HLSContext *c, struct playlist *pls)
         char iv[33], key[33], url[MAX_URL_SIZE];
         if (strcmp(seg->key, pls->key_url)) {
             URLContext *uc;
-            const char *proto_name = avio_find_protocol_name(seg->key);
-            if (!av_strstart(proto_name, "http", NULL) && !av_strstart(proto_name, "file", NULL)) {
-                ret = AVERROR_INVALIDDATA;
+            ret = check_url(seg->key);
+            if (ret < 0)
                 goto cleanup;
-            }
+
             if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ,
                            &pls->parent->interrupt_callback, &opts2) == 0) {
                 if (ffurl_read_complete(uc, pls->key, sizeof(pls->key))