Patchwork slirp: fix structure initialization in tcp_listen()

login
register
mail settings
Submitter Juha.Riihimaki@nokia.com
Date April 13, 2010, 6:16 a.m.
Message ID <1271139415-32694-1-git-send-email-juha.riihimaki@nokia.com>
Download mbox | patch
Permalink /patch/50023/
State New
Headers show

Comments

Juha.Riihimaki@nokia.com - April 13, 2010, 6:16 a.m.
From: Juha Riihimäki <juha.riihimaki@nokia.com>

A data structure of type sockaddr_in is allocated from stack but not
properly initialized. This may lead to a failure in the bind() call
later on. Fixed by filling the contents of the structure with zeroes
before using it.

Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
---
 slirp/socket.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
Blue Swirl - April 20, 2010, 4:47 p.m.
Thanks, applied.

On 4/13/10, juha.riihimaki@nokia.com <juha.riihimaki@nokia.com> wrote:
> From: Juha Riihimäki <juha.riihimaki@nokia.com>
>
>  A data structure of type sockaddr_in is allocated from stack but not
>  properly initialized. This may lead to a failure in the bind() call
>  later on. Fixed by filling the contents of the structure with zeroes
>  before using it.
>
>  Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
>  ---
>   slirp/socket.c |    1 +
>   1 files changed, 1 insertions(+), 0 deletions(-)
>
>  diff --git a/slirp/socket.c b/slirp/socket.c
>  index 8a257ac..eaad77a 100644
>  --- a/slirp/socket.c
>  +++ b/slirp/socket.c
>  @@ -587,6 +587,7 @@ tcp_listen(Slirp *slirp, u_int32_t haddr, u_int hport, u_int32_t laddr,
>         struct socket *so;
>         int s, opt = 1;
>         socklen_t addrlen = sizeof(addr);
>  +       memset(&addr, 0, addrlen);
>
>         DEBUG_CALL("tcp_listen");
>         DEBUG_ARG("haddr = %x", haddr);
>
> --
>  1.7.0.2
>
>
>
>

Patch

diff --git a/slirp/socket.c b/slirp/socket.c
index 8a257ac..eaad77a 100644
--- a/slirp/socket.c
+++ b/slirp/socket.c
@@ -587,6 +587,7 @@  tcp_listen(Slirp *slirp, u_int32_t haddr, u_int hport, u_int32_t laddr,
 	struct socket *so;
 	int s, opt = 1;
 	socklen_t addrlen = sizeof(addr);
+	memset(&addr, 0, addrlen);
 
 	DEBUG_CALL("tcp_listen");
 	DEBUG_ARG("haddr = %x", haddr);