diff mbox

[FFmpeg-devel,v2,1/5] avformat/http: ff_http_do_new_request() returns EINVAL if re-used with different hostname

Message ID 20171213003511.25342-2-ffmpeg@tmm1.net
State Accepted
Commit 28358e466d4f4bc54f8137e0597057f33100b236
Headers show

Commit Message

Aman Karmani Dec. 13, 2017, 12:35 a.m. UTC
From: Aman Gupta <aman@tmm1.net>

This will prevent improper use of ff_http_do_new_request() if the user
tries to send a request for a different host to a previously connected
persistent http/1.1 connection.
---
 libavformat/http.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Jeyapal, Karthick Dec. 13, 2017, 9:58 p.m. UTC | #1
>On 12/13/17, 6:05 AM, "Aman Gupta" <aman@tmm1.net on behalf of ffmpeg@tmm1.net> wrote:

>

>From: Aman Gupta <aman@tmm1.net>

>

>This will prevent improper use of ff_http_do_new_request() if the user

>tries to send a request for a different host to a previously connected

>persistent http/1.1 connection.

>---

> libavformat/http.c | 16 ++++++++++++++++

> 1 file changed, 16 insertions(+)

>

>diff --git a/libavformat/http.c b/libavformat/http.c

>index cf86adc617..a3c36423fc 100644

>--- a/libavformat/http.c

>+++ b/libavformat/http.c

>@@ -306,6 +306,22 @@ int ff_http_do_new_request(URLContext *h, const char *uri)

>     HTTPContext *s = h->priv_data;

>     AVDictionary *options = NULL;

>     int ret;

>+    char hostname1[1024], hostname2[1024], proto1[10], proto2[10];

>+    int port1, port2;

>+

>+    av_url_split(proto1, sizeof(proto1), NULL, 0,

>+                 hostname1, sizeof(hostname1), &port1,

>+                 NULL, 0, s->location);

>+    av_url_split(proto2, sizeof(proto2), NULL, 0,

>+                 hostname2, sizeof(hostname2), &port2,

>+                 NULL, 0, uri);

>+    if (port1 != port2 || strncmp(hostname1, hostname2, sizeof(hostname2)) != 0) {

>+        av_log(h, AV_LOG_ERROR, "Cannot reuse HTTP connection for different host: %s:%d != %s:%d\n",

>+            hostname1, port1,

>+            hostname2, port2

>+        );

>+        return AVERROR(EINVAL);

>+    }

Nice check!
It will prevent some bad server side errors/crashes, due to any misuse.
> 

>     ret = http_shutdown(h, h->flags);

>     if (ret < 0)

>-- 

>2.14.3 (Apple Git-98)
diff mbox

Patch

diff --git a/libavformat/http.c b/libavformat/http.c
index cf86adc617..a3c36423fc 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -306,6 +306,22 @@  int ff_http_do_new_request(URLContext *h, const char *uri)
     HTTPContext *s = h->priv_data;
     AVDictionary *options = NULL;
     int ret;
+    char hostname1[1024], hostname2[1024], proto1[10], proto2[10];
+    int port1, port2;
+
+    av_url_split(proto1, sizeof(proto1), NULL, 0,
+                 hostname1, sizeof(hostname1), &port1,
+                 NULL, 0, s->location);
+    av_url_split(proto2, sizeof(proto2), NULL, 0,
+                 hostname2, sizeof(hostname2), &port2,
+                 NULL, 0, uri);
+    if (port1 != port2 || strncmp(hostname1, hostname2, sizeof(hostname2)) != 0) {
+        av_log(h, AV_LOG_ERROR, "Cannot reuse HTTP connection for different host: %s:%d != %s:%d\n",
+            hostname1, port1,
+            hostname2, port2
+        );
+        return AVERROR(EINVAL);
+    }
 
     ret = http_shutdown(h, h->flags);
     if (ret < 0)