Opened 16 years ago

Closed 3 years ago

#2967 closed bug (fixed)

getpeername() succeeds on unconnected sockets

Reported by: bonefish Owned by: phoudoin
Priority: normal Milestone: R1/beta2
Component: Network & Internet/TCP Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: #15081 Blocking:
Platform: All

Description

hrev28311

A getpeername() after a connect() on a TCP socket succeeds even if

  • the socket is non-blocking and the connection has not been established, or
  • the socket is blocking and connect() timed out.

In either case getpeername() should fail with ENOTCONN.

The problem seems to be that getpeername() is fully implemented in the socket module and doesn't inquire the connection state. Or that the TCP module should set the peer address only when the connection is established and unset it when disconnected.

Change History (7)

comment:1 by phoudoin, 12 years ago

Owner: changed from axeld to phoudoin
Status: newassigned

comment:2 by phoudoin, 9 years ago

An easy fix is in src/add-ons/kernel/network/stack/net_socket.cpp

status_t
socket_getpeername(net_socket* _socket)
{
    net_socket_private* socket = (net_socket_private*)_socket;
    if (!socket->is_connected)
        return ENOTCONN;

    ...
}

Not great though, in the public socket API part of this module, net_socket_private is supposed to be unknown.

comment:3 by phoudoin, 9 years ago

Stupid fix, in fact, as it will break for connectionless sockets, like UDP. It means that, indeed, TCP module should not set peer address public until connected.

comment:4 by waddlesplash, 5 years ago

Blocking: 15081 added

comment:5 by waddlesplash, 5 years ago

Blocked By: 15081 added
Blocking: 15081 removed

comment:6 by pulkomandy, 5 years ago

Is this not fixed by hrev54132? In that case, what else needs to be done?

comment:7 by korli, 3 years ago

Milestone: R1R1/beta2
Resolution: fixed
Status: assignedclosed

combined with hrev54113 and hrev54118 this is fixed.

Note: See TracTickets for help on using tickets.