Azure / azure-c-shared-utility

Azure C SDKs common code
Other
111 stars 203 forks source link

Segmentation fault caused by initiate_socket_connection in adapters/socketio_berkeley.c when DNS resolution failed #636

Closed advantech-edgelink closed 1 year ago

advantech-edgelink commented 1 year ago
static int initiate_socket_connection(SOCKET_IO_INSTANCE* socket_io_instance)
{
    int result;
    int flags;
    struct addrinfo* addr = NULL;
    struct sockaddr_un addrInfoUn;

    if(socket_io_instance->address_type == ADDRESS_TYPE_IP)
    {
        ...
    }
    else
    {
        ...
    }

    if (socket_io_instance->address_type == ADDRESS_TYPE_IP)
    {
        socket_io_instance->socket = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
    }
    else
    {
        socket_io_instance->socket = socket(AF_UNIX, SOCK_STREAM, 0);
    }
    ...
}

The addr may be NULL when executing socket_io_instance->socket = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);

ewertons commented 1 year ago

Thanks for reporting, @advantech-edgelink ! A PR with the fix will come briefly.

RLeclair commented 1 year ago

Hi @advantech-edgelink, we've merged the PR with the fix, thank you again for reporting! Closing the issue now.