From ab42772a46e17d14204359a17234b2d9cee0ddb6 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 12 Sep 2012 16:40:08 +0100 Subject: [PATCH] Fix crash accessing a NULL URI when looking up auth credentials When auto-probing hypervisor drivers, the conn->uri field will initially be NULL. Care must be taken not to access members when doing auth lookups in the config file Signed-off-by: Daniel P. Berrange --- src/remote/remote_driver.c | 2 +- src/util/virauth.c | 2 +- src/util/viruri.h | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 3ee385c6e3..fc4c69615a 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -3726,7 +3726,7 @@ static int remoteAuthFillFromConfig(virConnectPtr conn, if (virAuthConfigLookup(state->config, "libvirt", - conn->uri->server, + VIR_URI_SERVER(conn->uri), credname, &value) < 0) goto cleanup; diff --git a/src/util/virauth.c b/src/util/virauth.c index 0d92a1d70a..6d9935d6e5 100644 --- a/src/util/virauth.c +++ b/src/util/virauth.c @@ -130,7 +130,7 @@ virAuthGetCredential(virConnectPtr conn, if (virAuthConfigLookup(config, servicename, - conn->uri->server, + VIR_URI_SERVER(conn->uri), credname, &tmp) < 0) goto cleanup; diff --git a/src/util/viruri.h b/src/util/viruri.h index aabd89454c..3cfc7d39d9 100644 --- a/src/util/viruri.h +++ b/src/util/viruri.h @@ -60,4 +60,6 @@ char *virURIFormatParams(virURIPtr uri); void virURIFree(virURIPtr uri); +# define VIR_URI_SERVER(uri) ((uri) && (uri)->server ? (uri)->server : "localhost") + #endif /* __VIR_URI_H__ */