udp: Fix crashes after adding AVOptions

Message ID 1426750242-90077-1-git-send-email-martin@martin.st
State Committed
Commit 8dc72eeaf647736c287b59a3856a11904bedd58b
Headers show

Commit Message

Martin Storsjö March 19, 2015, 7:30 a.m.
Add a missing AVClass member, check whether localaddr is null.
(Previously, localaddr was always a local stack buffer, while it
now also can be an avoption string which can be null.)

This fixes crashes when not passing any localaddr parameter.
---
 libavformat/udp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Luca Barbato March 19, 2015, 8:15 a.m. | #1
On 19/03/15 08:30, Martin Storsjö wrote:
> Add a missing AVClass member, check whether localaddr is null.
> (Previously, localaddr was always a local stack buffer, while it
> now also can be an avoption string which can be null.)
> 
> This fixes crashes when not passing any localaddr parameter.
> ---
>  libavformat/udp.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index e175a4b..321ed29 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -42,6 +42,7 @@
>  #endif
>  
>  typedef struct UDPContext {
> +    const AVClass *class;
>      int udp_fd;
>      int ttl;
>      int buffer_size;
> @@ -293,7 +294,7 @@ static int udp_socket_create(UDPContext *s, struct sockaddr_storage *addr,
>  
>      if (((struct sockaddr *) &s->dest_addr)->sa_family)
>          family = ((struct sockaddr *) &s->dest_addr)->sa_family;
> -    res0 = udp_resolve_host(localaddr[0] ? localaddr : NULL, s->local_port,
> +    res0 = udp_resolve_host((localaddr && localaddr[0]) ? localaddr : NULL, s->local_port,
>                              SOCK_DGRAM, family, AI_PASSIVE);
>      if (res0 == 0)
>          goto fail;
> 

Thanks for fixing it. Patch Ok.

lu

Patch

diff --git a/libavformat/udp.c b/libavformat/udp.c
index e175a4b..321ed29 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -42,6 +42,7 @@ 
 #endif
 
 typedef struct UDPContext {
+    const AVClass *class;
     int udp_fd;
     int ttl;
     int buffer_size;
@@ -293,7 +294,7 @@  static int udp_socket_create(UDPContext *s, struct sockaddr_storage *addr,
 
     if (((struct sockaddr *) &s->dest_addr)->sa_family)
         family = ((struct sockaddr *) &s->dest_addr)->sa_family;
-    res0 = udp_resolve_host(localaddr[0] ? localaddr : NULL, s->local_port,
+    res0 = udp_resolve_host((localaddr && localaddr[0]) ? localaddr : NULL, s->local_port,
                             SOCK_DGRAM, family, AI_PASSIVE);
     if (res0 == 0)
         goto fail;