Skip to contentSkip to conversation

qio_dns_resolver_lookup_sync() and SOCKET_ADDRESS_KIND_FD?

Qemu-devel Markus Armbruster 2 participants 2 messages Mar 23, 2017 – Apr 3, 2017

lore
Share & tools
lore
#0 lore raw

Ignorant question: does qio_dns_resolver_lookup_sync() do the right thing for SOCKET_ADDRESS_KIND_FD? The switch doesn't have a case for it, and it's unclear whether the default case is really meant for SOCKET_ADDRESS_KIND_FD in addition to impossible enumeration values.

Aside: impossible value means your program state is fatally compromised. I'd rather assert then.

int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver,
SocketAddress *addr, size_t *naddrs, SocketAddress ***addrs, Error **errp)

{
    switch (addr->type) {
    case SOCKET_ADDRESS_KIND_INET:
        return qio_dns_resolver_lookup_sync_inet(resolver,
                                                 addr,
                                                 naddrs,
                                                 addrs,
                                                 errp);

    case SOCKET_ADDRESS_KIND_UNIX:
    case SOCKET_ADDRESS_KIND_VSOCK:
        return qio_dns_resolver_lookup_sync_nop(resolver,
                                                addr,
                                                naddrs,
                                                addrs,
                                                errp);

    default:
        error_setg(errp, "Unknown socket address kind");
        return -1;
    }
}
#1 lore raw
Quoted 4 lines · Markus Armbruster

Ignorant question: does qio_dns_resolver_lookup_sync() do the right thing for SOCKET_ADDRESS_KIND_FD? The switch doesn't have a case for it, and it's unclear whether the default case is really meant for SOCKET_ADDRESS_KIND_FD in addition to impossible enumeration values.

No, it is wrong - it should do a 'no op' resolution, not return an error - ie KIND_FD handling should match KIND_UNIX/KIND_VSOCK.

Quoted 2 lines

Aside: impossible value means your program state is fatally compromised. I'd rather assert then.

Sure.

Quoted 21 lines

int qio_dns_resolver_lookup_sync(QIODNSResolver *resolver,
SocketAddress *addr, size_t *naddrs, SocketAddress ***addrs, Error **errp)

{
    switch (addr->type) {
    case SOCKET_ADDRESS_KIND_INET:
        return qio_dns_resolver_lookup_sync_inet(resolver,
                                                 addr,
                                                 naddrs,
                                                 addrs,
                                                 errp);

    case SOCKET_ADDRESS_KIND_UNIX:
    case SOCKET_ADDRESS_KIND_VSOCK:
        return qio_dns_resolver_lookup_sync_nop(resolver,
                                                addr,
                                                naddrs,
Quoted 8 lines
                                                addrs,
                                                errp);

    default:
        error_setg(errp, "Unknown socket address kind");
        return -1;
    }
}

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|