Undefined behaviour of connect(fd, NULL, 0);

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Neil Brown
Date: Wednesday, March 31, 2010 - 4:36 am

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
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Undefined behaviour of connect(fd, NULL, 0);, Neil Brown, (Wed Mar 31, 4:36 am)
Re: Undefined behaviour of connect(fd, NULL, 0);, Stephen Hemminger, (Wed Mar 31, 11:49 am)
Re: Undefined behaviour of connect(fd, NULL, 0);, Neil Brown, (Wed Mar 31, 1:24 pm)
Re: Undefined behaviour of connect(fd, NULL, 0);, Stephen Hemminger, (Wed Mar 31, 2:14 pm)
Re: Undefined behaviour of connect(fd, NULL, 0);, David Miller, (Wed Mar 31, 2:17 pm)
Re: Undefined behaviour of connect(fd, NULL, 0);, Neil Brown, (Wed Mar 31, 3:07 pm)
Re: Undefined behaviour of connect(fd, NULL, 0);, Changli Gao, (Wed Mar 31, 8:00 pm)
Re: Undefined behaviour of connect(fd, NULL, 0);, Neil Brown, (Wed Mar 31, 8:38 pm)
Re: Undefined behaviour of connect(fd, NULL, 0);, Changli Gao, (Wed Mar 31, 9:16 pm)
Re: Undefined behaviour of connect(fd, NULL, 0);, Changli Gao, (Wed Mar 31, 10:50 pm)
Re: Undefined behaviour of connect(fd, NULL, 0);, David Miller, (Thu Apr 1, 12:23 am)
Re: Undefined behaviour of connect(fd, NULL, 0);, Changli Gao, (Mon Apr 5, 2:23 am)
Re: Undefined behaviour of connect(fd, NULL, 0);, Eric Dumazet, (Mon Apr 5, 8:56 am)
Re: Undefined behaviour of connect(fd, NULL, 0);, Andreas Schwab, (Mon Apr 5, 9:25 am)
Re: Undefined behaviour of connect(fd, NULL, 0);, David Miller, (Mon Apr 5, 12:25 pm)