unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] smtp-dummy: clear sockaddr_in structures before use.
@ 2011-11-10 23:32 Tomi Ollila
  2011-11-12  2:40 ` Austin Clements
  0 siblings, 1 reply; 4+ messages in thread
From: Tomi Ollila @ 2011-11-10 23:32 UTC (permalink / raw)
  To: notmuch

Any junk bytes in sockaddr_in structures before passing those
to bind() or accept() functions may cause problems.
---
 test/smtp-dummy.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/test/smtp-dummy.c b/test/smtp-dummy.c
index 9da8202..38d1d62 100644
--- a/test/smtp-dummy.c
+++ b/test/smtp-dummy.c
@@ -159,6 +159,7 @@ main (int argc, char *argv[])
 		return 1;
 	}
 
+	memset (&addr, 0, sizeof addr);
 	addr.sin_family = AF_INET;
 	addr.sin_port = htons (25025);
 	addr.sin_addr = *(struct in_addr *) hostinfo->h_addr;
@@ -178,6 +179,7 @@ main (int argc, char *argv[])
 		return 1;
 	}
 
+	memset (&peer_addr, 0, sizeof peer_addr);
 	peer_addr_len = sizeof (peer_addr);
 	peer = accept (sock, (struct sockaddr *) &peer_addr, &peer_addr_len);
 	if (peer == -1) {
-- 
1.5.6.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] smtp-dummy: clear sockaddr_in structures before use.
  2011-11-10 23:32 [PATCH] smtp-dummy: clear sockaddr_in structures before use Tomi Ollila
@ 2011-11-12  2:40 ` Austin Clements
  2011-11-12  9:57   ` [PATCH] smtp-dummy: clear sockaddr_in structure before use in bind() Tomi Ollila
  0 siblings, 1 reply; 4+ messages in thread
From: Austin Clements @ 2011-11-12  2:40 UTC (permalink / raw)
  To: Tomi Ollila; +Cc: notmuch

Looks good and is the right thing to do.

The rest of smtp-dummy uses parens around sizeof operands, but whatever.

It's probably not necessary to clear peer_addr, since it's an
out-argument of accept and is never used (plus the example in bind(2)
doesn't), but there's no harm.

Quoth Tomi Ollila on Nov 11 at  1:32 am:
> Any junk bytes in sockaddr_in structures before passing those
> to bind() or accept() functions may cause problems.
> ---
>  test/smtp-dummy.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
> 
> diff --git a/test/smtp-dummy.c b/test/smtp-dummy.c
> index 9da8202..38d1d62 100644
> --- a/test/smtp-dummy.c
> +++ b/test/smtp-dummy.c
> @@ -159,6 +159,7 @@ main (int argc, char *argv[])
>  		return 1;
>  	}
>  
> +	memset (&addr, 0, sizeof addr);
>  	addr.sin_family = AF_INET;
>  	addr.sin_port = htons (25025);
>  	addr.sin_addr = *(struct in_addr *) hostinfo->h_addr;
> @@ -178,6 +179,7 @@ main (int argc, char *argv[])
>  		return 1;
>  	}
>  
> +	memset (&peer_addr, 0, sizeof peer_addr);
>  	peer_addr_len = sizeof (peer_addr);
>  	peer = accept (sock, (struct sockaddr *) &peer_addr, &peer_addr_len);
>  	if (peer == -1) {

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] smtp-dummy: clear sockaddr_in structure before use in bind()
  2011-11-12  2:40 ` Austin Clements
@ 2011-11-12  9:57   ` Tomi Ollila
  2011-11-12 12:55     ` David Bremner
  0 siblings, 1 reply; 4+ messages in thread
From: Tomi Ollila @ 2011-11-12  9:57 UTC (permalink / raw)
  To: Austin Clements; +Cc: notmuch

Any junk bytes in sockaddr_in structure before passing that
to bind() system call may cause problems.
---

Thanks Austin. Consistent style matters... And dropped the peer_addr
setting after reading accept(2) namual page.

 test/smtp-dummy.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/test/smtp-dummy.c b/test/smtp-dummy.c
index 9da8202..1778a45 100644
--- a/test/smtp-dummy.c
+++ b/test/smtp-dummy.c
@@ -159,6 +159,7 @@ main (int argc, char *argv[])
 		return 1;
 	}
 
+	memset (&addr, 0, sizeof (addr));
 	addr.sin_family = AF_INET;
 	addr.sin_port = htons (25025);
 	addr.sin_addr = *(struct in_addr *) hostinfo->h_addr;
-- 
1.5.6.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] smtp-dummy: clear sockaddr_in structure before use in bind()
  2011-11-12  9:57   ` [PATCH] smtp-dummy: clear sockaddr_in structure before use in bind() Tomi Ollila
@ 2011-11-12 12:55     ` David Bremner
  0 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2011-11-12 12:55 UTC (permalink / raw)
  To: Tomi Ollila, Austin Clements; +Cc: notmuch

On Sat, 12 Nov 2011 11:57:22 +0200, Tomi Ollila <tomi.ollila@iki.fi> wrote:
> Any junk bytes in sockaddr_in structure before passing that
> to bind() system call may cause problems.
> ---

Pushed the second version.

d

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-11-12 12:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-10 23:32 [PATCH] smtp-dummy: clear sockaddr_in structures before use Tomi Ollila
2011-11-12  2:40 ` Austin Clements
2011-11-12  9:57   ` [PATCH] smtp-dummy: clear sockaddr_in structure before use in bind() Tomi Ollila
2011-11-12 12:55     ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).