[libvirt] [PATCH] conf: return immediately on error in dhcp host element

If and error was encountered parsing a dhcp host entry mac address or name, parsing would continue and log a less descriptive error that might make it more difficult to notice the true nature of the problem. This patch returns immediately on logging the first error. --- src/conf/network_conf.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 0333141..0fa58f8 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -430,6 +430,7 @@ virNetworkDHCPRangeDefParseXML(const char *networkName, _("Cannot parse MAC address '%s' in network '%s'"), mac, networkName); VIR_FREE(mac); + return -1; } name = virXMLPropString(cur, "name"); if ((name != NULL) && (!c_isalpha(name[0]))) { @@ -437,6 +438,7 @@ virNetworkDHCPRangeDefParseXML(const char *networkName, _("Cannot use name address '%s' in network '%s'"), name, networkName); VIR_FREE(name); + return -1; } /* * You need at least one MAC address or one host name -- 1.7.7.6

On 03/19/2012 11:32 AM, Laine Stump wrote:
If and error was encountered parsing a dhcp host entry mac address or name, parsing would continue and log a less descriptive error that might make it more difficult to notice the true nature of the problem.
This patch returns immediately on logging the first error. --- src/conf/network_conf.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 0333141..0fa58f8 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -430,6 +430,7 @@ virNetworkDHCPRangeDefParseXML(const char *networkName, _("Cannot parse MAC address '%s' in network '%s'"), mac, networkName); VIR_FREE(mac); + return -1; } name = virXMLPropString(cur, "name"); if ((name != NULL) && (!c_isalpha(name[0]))) { @@ -437,6 +438,7 @@ virNetworkDHCPRangeDefParseXML(const char *networkName, _("Cannot use name address '%s' in network '%s'"), name, networkName); VIR_FREE(name); + return -1;
Memory leak - you just leaked mac. Needs a v2. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

If an error was encountered parsing a dhcp host entry mac address or name, parsing would continue and log a less descriptive error that might make it more difficult to notice the true nature of the problem. This patch returns immediately on logging the first error. --- src/conf/network_conf.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 0333141..4341f11 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -430,13 +430,16 @@ virNetworkDHCPRangeDefParseXML(const char *networkName, _("Cannot parse MAC address '%s' in network '%s'"), mac, networkName); VIR_FREE(mac); + return -1; } name = virXMLPropString(cur, "name"); if ((name != NULL) && (!c_isalpha(name[0]))) { virNetworkReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot use name address '%s' in network '%s'"), name, networkName); + VIR_FREE(mac); VIR_FREE(name); + return -1; } /* * You need at least one MAC address or one host name -- 1.7.7.6

On 03/19/2012 12:46 PM, Laine Stump wrote:
If an error was encountered parsing a dhcp host entry mac address or name, parsing would continue and log a less descriptive error that might make it more difficult to notice the true nature of the problem.
This patch returns immediately on logging the first error. --- src/conf/network_conf.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 0333141..4341f11 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -430,13 +430,16 @@ virNetworkDHCPRangeDefParseXML(const char *networkName, _("Cannot parse MAC address '%s' in network '%s'"), mac, networkName); VIR_FREE(mac); + return -1; } name = virXMLPropString(cur, "name"); if ((name != NULL) && (!c_isalpha(name[0]))) { virNetworkReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot use name address '%s' in network '%s'"), name, networkName); + VIR_FREE(mac); VIR_FREE(name); + return -1;
ACK. I was debating if it would have been any cleaner to have a cleanup: label, but then you start having to do major refactoring to take advantage of it, at which point this patch would no longer be quite so small. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 03/19/2012 03:49 PM, Eric Blake wrote:
On 03/19/2012 12:46 PM, Laine Stump wrote:
If an error was encountered parsing a dhcp host entry mac address or name, parsing would continue and log a less descriptive error that might make it more difficult to notice the true nature of the problem.
This patch returns immediately on logging the first error. --- src/conf/network_conf.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 0333141..4341f11 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -430,13 +430,16 @@ virNetworkDHCPRangeDefParseXML(const char *networkName, _("Cannot parse MAC address '%s' in network '%s'"), mac, networkName); VIR_FREE(mac); + return -1; } name = virXMLPropString(cur, "name"); if ((name != NULL) && (!c_isalpha(name[0]))) { virNetworkReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot use name address '%s' in network '%s'"), name, networkName); + VIR_FREE(mac); VIR_FREE(name); + return -1; ACK. I was debating if it would have been any cleaner to have a cleanup: label, but then you start having to do major refactoring to take advantage of it, at which point this patch would no longer be quite so small.
Yeah, I go through the same thought process every time I see cleanup code like this. It's so much more difficult to introduce leaks when there is a single exit from the function and everything is always cleaned up. Pushed. Thanks!
participants (2)
-
Eric Blake
-
Laine Stump