[libvirt] [PATCH] Fix crash accessing a NULL URI when looking up auth credentials
Daniel P. Berrange
berrange at redhat.com
Wed Sep 12 15:41:16 UTC 2012
From: "Daniel P. Berrange" <berrange at redhat.com>
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
---
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 cf1f079..8c6c807 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3281,7 +3281,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 5539c3c..ff8d0d4 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 571bf3c..de927fa 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__ */
--
1.7.11.4
More information about the libvir-list
mailing list