diff mbox

[FFmpeg-devel,2/3] udp: Check the port number provided by av_url_split as per docs

Message ID 1511364522-40586-3-git-send-email-derekb@vimeo.com
State New
Headers show

Commit Message

Derek Buitenhuis Nov. 22, 2017, 3:28 p.m. UTC
Signed-off-by: Derek Buitenhuis <derekb@vimeo.com>
---
 libavformat/udp.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Michael Niedermayer Nov. 23, 2017, 11:28 p.m. UTC | #1
On Wed, Nov 22, 2017 at 03:28:41PM +0000, Derek Buitenhuis wrote:
> Signed-off-by: Derek Buitenhuis <derekb@vimeo.com>
> ---
>  libavformat/udp.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index 0dde035..7bbd282 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -443,6 +443,10 @@ int ff_udp_set_remote_url(URLContext *h, const char *uri)
>      const char *p;
>  
>      av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
> +    if (port < 0) {
> +        av_log(s, AV_LOG_ERROR, "No valid port number found in URL.\n");
> +        return AVERROR(EINVAL);
> +    }
>  
>      /* set the destination address */
>      s->dest_addr_len = udp_set_url(h, &s->dest_addr, hostname, port);
> @@ -798,6 +802,10 @@ static int udp_open(URLContext *h, const char *uri, int flags)
>  
>      /* fill the dest addr */
>      av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
> +    if (port < 0) {
> +        av_log(h, AV_LOG_ERROR, "Missing or invalid port provided in URL.\n");
> +        return AVERROR(EINVAL);
> +    }
>  
>      /* XXX: fix av_url_split */
>      if (hostname[0] == '\0' || hostname[0] == '?') {
> -- 

this seems to break rtp / rtsp

ive traced it to
ff_rtsp_make_setup_request() calling ffurl_open_whitelist() without
a port

[...]
Derek Buitenhuis Nov. 24, 2017, 2:10 p.m. UTC | #2
On 11/23/2017 11:28 PM, Michael Niedermayer wrote:
> this seems to break rtp / rtsp
> 
> ive traced it to
> ff_rtsp_make_setup_request() calling ffurl_open_whitelist() without
> a port

Looking at:

    https://github.com/FFmpeg/FFmpeg/blob/1e27837265702b63db65122e97178a0ca4d25e05/libavformat/rtsp.c#L1466-L1476

It seems it's using '?localport=<port>' instead of specifying a port...

Is there a particular reason for this? It seems... odd. I don't know the RTSP
code, really.

- Derek
diff mbox

Patch

diff --git a/libavformat/udp.c b/libavformat/udp.c
index 0dde035..7bbd282 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -443,6 +443,10 @@  int ff_udp_set_remote_url(URLContext *h, const char *uri)
     const char *p;
 
     av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
+    if (port < 0) {
+        av_log(s, AV_LOG_ERROR, "No valid port number found in URL.\n");
+        return AVERROR(EINVAL);
+    }
 
     /* set the destination address */
     s->dest_addr_len = udp_set_url(h, &s->dest_addr, hostname, port);
@@ -798,6 +802,10 @@  static int udp_open(URLContext *h, const char *uri, int flags)
 
     /* fill the dest addr */
     av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, NULL, 0, uri);
+    if (port < 0) {
+        av_log(h, AV_LOG_ERROR, "Missing or invalid port provided in URL.\n");
+        return AVERROR(EINVAL);
+    }
 
     /* XXX: fix av_url_split */
     if (hostname[0] == '\0' || hostname[0] == '?') {