Fix panic caused by invalid address for Bind in packet sockets.
PiperOrigin-RevId: 298476533
This commit is contained in:
parent
d80b6a6e49
commit
43abb24657
|
@ -712,6 +712,10 @@ func (s *SocketOperations) Connect(t *kernel.Task, sockaddr []byte, blocking boo
|
|||
// Bind implements the linux syscall bind(2) for sockets backed by
|
||||
// tcpip.Endpoint.
|
||||
func (s *SocketOperations) Bind(t *kernel.Task, sockaddr []byte) *syserr.Error {
|
||||
if len(sockaddr) < 2 {
|
||||
return syserr.ErrInvalidArgument
|
||||
}
|
||||
|
||||
family := usermem.ByteOrder.Uint16(sockaddr)
|
||||
var addr tcpip.FullAddress
|
||||
|
||||
|
|
|
@ -417,6 +417,19 @@ TEST_P(CookedPacketTest, BindDrop) {
|
|||
EXPECT_THAT(RetryEINTR(poll)(&pfd, 1, 1000), SyscallSucceedsWithValue(0));
|
||||
}
|
||||
|
||||
// Bind with invalid address.
|
||||
TEST_P(CookedPacketTest, BindFail) {
|
||||
// Null address.
|
||||
ASSERT_THAT(bind(socket_, nullptr, sizeof(struct sockaddr)),
|
||||
SyscallFailsWithErrno(EFAULT));
|
||||
|
||||
// Address of size 1.
|
||||
uint8_t addr = 0;
|
||||
ASSERT_THAT(
|
||||
bind(socket_, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)),
|
||||
SyscallFailsWithErrno(EINVAL));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(AllInetTests, CookedPacketTest,
|
||||
::testing::Values(ETH_P_IP, ETH_P_ALL));
|
||||
|
||||
|
|
Loading…
Reference in New Issue