netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Undefined behaviour of connect(fd, NULL, 0);
@ 2010-03-31 11:36 Neil Brown
  2010-03-31 18:49 ` Stephen Hemminger
  0 siblings, 1 reply; 15+ messages in thread
From: Neil Brown @ 2010-03-31 11:36 UTC (permalink / raw)
  To: netdev


Hi Netdev.

We have a customer who was reporting strangely unpredictable behaviour of an
in-house application that used networking.

It called connect on a non-blocking socket and subsequently called
   connect(fd, NULL, 0)

to check if the connection had succeeded.
This would sometime "work" and sometimes close the connection.

Looking at the code (sys_connect, move_addr_to_kernel, inet_stream_connect),
it seems that in this case an uninitialised on-stack address is passed
to inet_stream_connect and it makes a decision based on ->sa_family (which is
uninitialised).

It seems clear that connect(fd, NULL, 0) is the wrong thing to do in this
circumstance, but I think it would be good if it failed consistently rather
than unpredictably.

Would it be appropriate for move_addr_to_kernel to zero out the remainder of
the address?
   memset(kaddr+ulen, 0, MAX_SOCK_ADDR-ulen);
??

Then connect(fd, NULL, 0) would always break the connection.

Thanks,
NeilBrown

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

end of thread, other threads:[~2010-04-05 19:25 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-31 11:36 Undefined behaviour of connect(fd, NULL, 0); Neil Brown
2010-03-31 18:49 ` Stephen Hemminger
2010-03-31 20:24   ` Neil Brown
2010-03-31 21:14     ` Stephen Hemminger
2010-03-31 21:17     ` David Miller
2010-03-31 22:07       ` Neil Brown
2010-04-01  3:00         ` Changli Gao
2010-04-01  3:38           ` Neil Brown
2010-04-01  4:16             ` Changli Gao
2010-04-01  5:50               ` Changli Gao
2010-04-01  7:23               ` David Miller
2010-04-05  9:23                 ` Changli Gao
2010-04-05 15:56                   ` Eric Dumazet
2010-04-05 16:25                     ` Andreas Schwab
2010-04-05 19:25                   ` David Miller

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 NNTP newsgroup(s).