[libvirt PATCH 0/3] openvz: fix NULL hostname usage

GCC on RHEL 8 emits a warning. See the first patch. Ján Tomko (3): openvzDomainMigratePrepare3Params: correctly use hostname openvzDomainMigratePrepare3Params: remove else after goto openvzDomainMigratePrepare3Params: use g_auto src/openvz/openvz_driver.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.26.2

In case no uri_in was supplied, we forgot to set the hostname to the current hostname and formatted a useless uri_out. src/util/glibcompat.h:57:26: error: ‘%s’ directive argument is null [-Werror=format-overflow=] 57 | # define g_strdup_printf vir_g_strdup_printf src/openvz/openvz_driver.c:2136:16: note: in expansion of macro ‘g_strdup_printf’ 2136 | *uri_out = g_strdup_printf("ssh://%s", hostname); Signed-off-by: Ján Tomko <jtomko@redhat.com> Reported-by: Jaroslav Suchanek <jsuchane@redhat.com> Fixes: e3c626a61d6c3d808555653684c0fb1e7c4d74ec --- src/openvz/openvz_driver.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 62bf418027..4fa7511f88 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -2113,6 +2113,8 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn, " but migration requires an FQDN")); goto error; } + + hostname = my_hostname; } else { uri = virURIParse(uri_in); -- 2.26.2

We jump to the error label if the 'if' condition is true. Remove the explicit else to make it more obvious that 'hostname' is filled on both branches of 'if (!uri_in)'. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/openvz/openvz_driver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 4fa7511f88..c6b7e21e7a 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -2130,9 +2130,9 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn, _("missing host in migration URI: %s"), uri_in); goto error; - } else { - hostname = uri->server; } + + hostname = uri->server; } *uri_out = g_strdup_printf("ssh://%s", hostname); -- 2.26.2

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/openvz/openvz_driver.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index c6b7e21e7a..96535a8216 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -2067,9 +2067,9 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn, const char *uri_in = NULL; virDomainDefPtr def = NULL; virDomainObjPtr vm = NULL; - char *my_hostname = NULL; + g_autofree char *my_hostname = NULL; const char *hostname = NULL; - virURIPtr uri = NULL; + g_autoptr(virURI) uri = NULL; int ret = -1; if (virTypedParamsValidate(params, nparams, OPENVZ_MIGRATION_PARAMETERS) < 0) @@ -2146,8 +2146,6 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn, virDomainObjListRemove(driver->domains, vm); done: - VIR_FREE(my_hostname); - virURIFree(uri); virDomainObjEndAPI(&vm); return ret; } -- 2.26.2

On Thu, Nov 19, 2020 at 11:33:26AM +0100, Ján Tomko wrote:
GCC on RHEL 8 emits a warning. See the first patch.
Ján Tomko (3): openvzDomainMigratePrepare3Params: correctly use hostname openvzDomainMigratePrepare3Params: remove else after goto openvzDomainMigratePrepare3Params: use g_auto
Reviewed-by: Erik Skultety <eskultet@redhat.com>
participants (2)
-
Erik Skultety
-
Ján Tomko