debug: avoid null dereference on uuid lookup api

Detected by Coverity.  Commit a98d8f0d tried to make uuid debugging
more robust, but missed some APIs.  And on the APIs that it visited,
the mere act of preparing the debug message ends up dereferencing
uuid prior to the null check.  Which means the APIs which are supposed
to gracefully reject NULL arguments now end up with SIGSEGV.

* src/libvirt.c (VIR_UUID_DEBUG): New macro.
(virDomainLookupByUUID, virDomainLookupByUUIDString)
(virNetworkLookupByUUID, virNetworkLookupByUUIDString)
(virStoragePoolLookupByUUID, virStoragePoolLookupByUUIDString)
(virSecretLookupByUUID, virSecretLookupByUUIDString)
(virNWFilterLookupByUUID, virNWFilterLookupByUUIDString): Avoid
null dereference.
This commit is contained in:
Eric Blake 2011-06-06 11:55:43 -06:00
parent f73198df3b
commit 2ed0c94dbc

View File

@ -362,6 +362,22 @@ static struct gcry_thread_cbs virTLSThreadImpl = {
VIR_HAS_COMMA(__VA_ARGS__), \
__VA_ARGS__)
/**
* VIR_UUID_DEBUG:
* @conn: connection
* @uuid: possibly null UUID array
*/
#define VIR_UUID_DEBUG(conn, uuid) \
do { \
if (uuid) { \
char _uuidstr[VIR_UUID_STRING_BUFLEN]; \
virUUIDFormat(uuid, _uuidstr); \
VIR_DEBUG("conn=%p, uuid=%s", conn, _uuidstr); \
} else { \
VIR_DEBUG("conn=%p, uuid=(null)", conn); \
} \
} while (0)
/**
* virInitialize:
*
@ -1876,10 +1892,7 @@ error:
virDomainPtr
virDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(uuid, uuidstr);
VIR_DEBUG("conn=%p, uuid=%s", conn, uuidstr);
VIR_UUID_DEBUG(conn, uuid);
virResetLastError();
@ -1922,7 +1935,7 @@ virDomainPtr
virDomainLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
{
unsigned char uuid[VIR_UUID_BUFLEN];
VIR_DEBUG("conn=%p, uuidstr=%s", conn, uuidstr);
VIR_DEBUG("conn=%p, uuidstr=%s", conn, NULLSTR(uuidstr));
virResetLastError();
@ -7493,10 +7506,7 @@ error:
virNetworkPtr
virNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
{
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(uuid, uuidstr);
VIR_DEBUG("conn=%p, uuid=%s", conn, uuidstr);
VIR_UUID_DEBUG(conn, uuid);
virResetLastError();
@ -7539,7 +7549,7 @@ virNetworkPtr
virNetworkLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
{
unsigned char uuid[VIR_UUID_BUFLEN];
VIR_DEBUG("conn=%p, uuidstr=%s", conn, uuidstr);
VIR_DEBUG("conn=%p, uuidstr=%s", conn, NULLSTR(uuidstr));
virResetLastError();
@ -9235,7 +9245,7 @@ virStoragePoolPtr
virStoragePoolLookupByUUID(virConnectPtr conn,
const unsigned char *uuid)
{
VIR_DEBUG("conn=%p, uuid=%s", conn, uuid);
VIR_UUID_DEBUG(conn, uuid);
virResetLastError();
@ -9279,7 +9289,7 @@ virStoragePoolLookupByUUIDString(virConnectPtr conn,
const char *uuidstr)
{
unsigned char uuid[VIR_UUID_BUFLEN];
VIR_DEBUG("conn=%p, uuidstr=%s", conn, uuidstr);
VIR_DEBUG("conn=%p, uuidstr=%s", conn, NULLSTR(uuidstr));
virResetLastError();
@ -11766,7 +11776,7 @@ error:
virSecretPtr
virSecretLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
{
VIR_DEBUG("conn=%p, uuid=%s", conn, uuid);
VIR_UUID_DEBUG(conn, uuid);
virResetLastError();
@ -11811,7 +11821,7 @@ virSecretPtr
virSecretLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
{
unsigned char uuid[VIR_UUID_BUFLEN];
VIR_DEBUG("conn=%p, uuidstr=%s", conn, uuidstr);
VIR_DEBUG("conn=%p, uuidstr=%s", conn, NULLSTR(uuidstr));
virResetLastError();
@ -13422,7 +13432,7 @@ error:
virNWFilterPtr
virNWFilterLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
{
VIR_DEBUG("conn=%p, uuid=%s", conn, uuid);
VIR_UUID_DEBUG(conn, uuid);
virResetLastError();
@ -13465,7 +13475,7 @@ virNWFilterPtr
virNWFilterLookupByUUIDString(virConnectPtr conn, const char *uuidstr)
{
unsigned char uuid[VIR_UUID_BUFLEN];
VIR_DEBUG("conn=%p, uuidstr=%s", conn, uuidstr);
VIR_DEBUG("conn=%p, uuidstr=%s", conn, NULLSTR(uuidstr));
virResetLastError();