diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 945c1f4a3704e36114a8e342cec719896ccaf4fa..fe937117f8937705c14428ab4228d49b40370abb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2515,12 +2515,8 @@ virDomainChrDefParseTargetXML(virCapsPtr caps, goto error; } - if (virSocketParseAddr(addrStr, def->target.addr, AF_UNSPEC) < 0) { - virDomainReportError(VIR_ERR_XML_ERROR, - _("%s is not a valid address"), - addrStr); + if (virSocketParseAddr(addrStr, def->target.addr, AF_UNSPEC) < 0) goto error; - } if (def->target.addr->data.stor.ss_family != AF_INET) { virDomainReportError(VIR_ERR_CONFIG_UNSUPPORTED, diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index f209dad7ab0aa824cdffe978dd6bc95478e052ba..fe52f95a86e939535ce04a4c484c1a57bf9dec6e 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -244,22 +244,14 @@ virNetworkDHCPRangeDefParseXML(virNetworkDefPtr def, } if (virSocketParseAddr(start, &saddr, AF_UNSPEC) < 0) { - virNetworkReportError(VIR_ERR_XML_ERROR, - _("cannot parse dhcp start address '%s'"), - start); xmlFree(start); xmlFree(end); - cur = cur->next; - continue; + return -1; } if (virSocketParseAddr(end, &eaddr, AF_UNSPEC) < 0) { - virNetworkReportError(VIR_ERR_XML_ERROR, - _("cannot parse dhcp end address '%s'"), - end); xmlFree(start); xmlFree(end); - cur = cur->next; - continue; + return -1; } range = virSocketGetRange(&saddr, &eaddr); @@ -269,8 +261,7 @@ virNetworkDHCPRangeDefParseXML(virNetworkDefPtr def, start, end); xmlFree(start); xmlFree(end); - cur = cur->next; - continue; + return -1; } if (VIR_REALLOC_N(def->ranges, def->nranges + 1) < 0) { diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index ac91c576effe84442466f650b8fdcc2f26552407..37ed32e701a5e0e7e3db495949755626e092eee0 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -1046,19 +1046,11 @@ static int networkCheckRouteCollision(virNetworkObjPtr network) if (!network->def->ipAddress || !network->def->netmask) return 0; - if (virSocketParseAddr(network->def->ipAddress, &inaddress, AF_UNSPEC) < 0) { - networkReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse IP address '%s'"), - network->def->ipAddress); + if (virSocketParseAddr(network->def->ipAddress, &inaddress, AF_UNSPEC) < 0) goto error; - } - if (virSocketParseAddr(network->def->netmask, &innetmask, AF_UNSPEC) < 0) { - networkReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse netmask '%s'"), - network->def->netmask); + if (virSocketParseAddr(network->def->netmask, &innetmask, AF_UNSPEC) < 0) goto error; - } if (inaddress.data.stor.ss_family != AF_INET || innetmask.data.stor.ss_family != AF_INET) { diff --git a/src/util/network.c b/src/util/network.c index 0c7cb633561c5283d4840caf3891294a6d5b3564..81ac22805db20a8a26ad92492fc43d3ae59eb139 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -77,15 +77,28 @@ virSocketParseAddr(const char *val, virSocketAddrPtr addr, int family) { int len; struct addrinfo hints; struct addrinfo *res = NULL; + int err; - if (val == NULL) - return(-1); + if (val == NULL) { + virSocketError(VIR_ERR_INVALID_ARG, _("Missing address")); + return -1; + } memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_flags = AI_NUMERICHOST; - if ((getaddrinfo(val, NULL, &hints, &res) != 0) || (res == NULL)) { - return(-1); + if ((err = getaddrinfo(val, NULL, &hints, &res)) != 0) { + virSocketError(VIR_ERR_SYSTEM_ERROR, + _("Cannot parse socket address '%s': %s"), + val, gai_strerror(err)); + return -1; + } + + if (res == NULL) { + virSocketError(VIR_ERR_SYSTEM_ERROR, + _("No socket addresses found for '%s'"), + val); + return -1; } len = res->ai_addrlen;