1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

build: add compiler attributes to virUUIDParse

Coverity complained that most, but not all, clients of virUUIDParse
were checking for errors.  Silence those coverity warnings by
explicitly marking the cases where we trust the input, and fixing
one instance that really should have been checking.  In particular,
this silences a rather large percentage of the warnings I saw on my
most recent Coverity analysis run.

* src/util/uuid.h (virUUIDParse): Enforce rules.
* src/util/uuid.c (virUUIDParse): Drop impossible check; at least
Coverity will detect if we break rules and pass NULL.
* src/xenapi/xenapi_driver.c (xenapiDomainCreateXML)
(xenapiDomainLookupByID, xenapiDomainLookupByName)
(xenapiDomainDefineXML): Ignore return when we trust data source.
* src/vbox/vbox_tmpl.c (nsIDtoChar, vboxIIDToUUID_v3_x)
(vboxCallbackOnMachineStateChange)
(vboxCallbackOnMachineRegistered, vboxStoragePoolLookupByName):
Likewise.
* src/node_device/node_device_hal.c (gather_system_cap): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxpr): Check for errors.
This commit is contained in:
Eric Blake 2011-10-12 17:24:52 -06:00
parent 72851bb9ef
commit 430156cf32
6 changed files with 19 additions and 18 deletions

View File

@ -38,6 +38,7 @@
#include "pci.h"
#include "logging.h"
#include "node_device_driver.h"
#include "ignore-value.h"
#define VIR_FROM_THIS VIR_FROM_NODEDEV
@ -299,7 +300,7 @@ static int gather_system_cap(LibHalContext *ctx, const char *udi,
(void)get_str_prop(ctx, udi, "system.hardware.serial",
&d->system.hardware.serial);
if (get_str_prop(ctx, udi, "system.hardware.uuid", &uuidstr) == 0) {
(void)virUUIDParse(uuidstr, d->system.hardware.uuid);
ignore_value(virUUIDParse(uuidstr, d->system.hardware.uuid));
VIR_FREE(uuidstr);
}
(void)get_str_prop(ctx, udi, "system.firmware.vendor",

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2007, 2008, 2009, 2010 Red Hat, Inc.
* Copyright (C) 2007-2011 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -129,9 +129,6 @@ virUUIDParse(const char *uuidstr, unsigned char *uuid) {
const char *cur;
int i;
if ((uuidstr == NULL) || (uuid == NULL))
return(-1);
/*
* do a liberal scan allowing '-' and ' ' anywhere between character
* pairs, and surrounding whitespace, as long as there are exactly

View File

@ -32,7 +32,8 @@ int virUUIDIsValid(unsigned char *uuid);
int virUUIDGenerate(unsigned char *uuid);
int virUUIDParse(const char *uuidstr,
unsigned char *uuid);
unsigned char *uuid)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
void virUUIDFormat(const unsigned char *uuid,
char *uuidstr) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

View File

@ -300,7 +300,7 @@ static void nsIDtoChar(unsigned char *uuid, const nsID *iid) {
}
uuidstrdst[VIR_UUID_STRING_BUFLEN-1] = '\0';
virUUIDParse(uuidstrdst, uuid);
ignore_value(virUUIDParse(uuidstrdst, uuid));
}
static void nsIDFromChar(nsID *iid, const unsigned char *uuid) {
@ -339,7 +339,7 @@ static void nsIDFromChar(nsID *iid, const unsigned char *uuid) {
}
uuidstrdst[VIR_UUID_STRING_BUFLEN-1] = '\0';
virUUIDParse(uuidstrdst, uuidinterim);
ignore_value(virUUIDParse(uuidstrdst, uuidinterim));
memcpy(iid, uuidinterim, VIR_UUID_BUFLEN);
}
@ -511,7 +511,7 @@ vboxIIDToUUID_v3_x(vboxGlobalData *data, vboxIID_v3_x *iid,
data->pFuncs->pfnUtf16ToUtf8(iid->value, &utf8);
virUUIDParse(utf8, uuid);
ignore_value(virUUIDParse(utf8, uuid));
data->pFuncs->pfnUtf8Free(utf8);
}
@ -6558,7 +6558,7 @@ vboxCallbackOnMachineStateChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
unsigned char uuid[VIR_UUID_BUFLEN];
g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(machineId, &machineIdUtf8);
virUUIDParse(machineIdUtf8, uuid);
ignore_value(virUUIDParse(machineIdUtf8, uuid));
dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid);
if (dom) {
@ -6686,7 +6686,7 @@ vboxCallbackOnMachineRegistered(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED,
unsigned char uuid[VIR_UUID_BUFLEN];
g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(machineId, &machineIdUtf8);
virUUIDParse(machineIdUtf8, uuid);
ignore_value(virUUIDParse(machineIdUtf8, uuid));
dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid);
if (dom) {
@ -7983,7 +7983,7 @@ static virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const c
unsigned char uuid[VIR_UUID_BUFLEN];
const char *uuidstr = "1deff1ff-1481-464f-967f-a50fe8936cc4";
virUUIDParse(uuidstr, uuid);
ignore_value(virUUIDParse(uuidstr, uuid));
ret = virGetStoragePool(conn, name, uuid);
}

View File

@ -40,6 +40,7 @@
#include "xenapi_driver.h"
#include "xenapi_driver_private.h"
#include "xenapi_utils.h"
#include "ignore-value.h"
#define VIR_FROM_THIS VIR_FROM_XENAPI
@ -528,7 +529,7 @@ xenapiDomainCreateXML (virConnectPtr conn,
virDomainDefFree(defPtr);
if (record) {
unsigned char raw_uuid[VIR_UUID_BUFLEN];
virUUIDParse(record->uuid, raw_uuid);
ignore_value(virUUIDParse(record->uuid, raw_uuid));
if (vm) {
if (xen_vm_start(session, vm, false, false)) {
domP = virGetDomain(conn, record->name_label, raw_uuid);
@ -574,13 +575,13 @@ xenapiDomainLookupByID (virConnectPtr conn, int id)
xen_session_get_this_host(session, &host, session);
if (host != NULL && session->ok) {
xen_host_get_resident_vms(session, &result, host);
if (result != NULL ) {
if (result != NULL) {
for (i = 0; i < result->size; i++) {
xen_vm_get_domid(session, &domID, result->contents[i]);
if (domID == id) {
xen_vm_get_record(session, &record, result->contents[i]);
xen_vm_get_uuid(session, &uuid, result->contents[i]);
virUUIDParse(uuid, raw_uuid);
ignore_value(virUUIDParse(uuid, raw_uuid));
domP = virGetDomain(conn, record->name_label, raw_uuid);
if (domP) {
int64_t domid = -1;
@ -672,7 +673,7 @@ xenapiDomainLookupByName (virConnectPtr conn,
vm = vms->contents[0];
xen_vm_get_uuid(session, &uuid, vm);
if (uuid!=NULL) {
virUUIDParse(uuid, raw_uuid);
ignore_value(virUUIDParse(uuid, raw_uuid));
domP = virGetDomain(conn, name, raw_uuid);
if (domP != NULL) {
int64_t domid = -1;
@ -1683,7 +1684,7 @@ xenapiDomainDefineXML (virConnectPtr conn, const char *xml)
}
if (record != NULL) {
unsigned char raw_uuid[VIR_UUID_BUFLEN];
virUUIDParse(record->uuid, raw_uuid);
ignore_value(virUUIDParse(record->uuid, raw_uuid));
domP = virGetDomain(conn, record->name_label, raw_uuid);
if (!domP && !session->ok)
xenapiSessionErrorHandler(conn, VIR_ERR_NO_DOMAIN, NULL);

View File

@ -1094,7 +1094,8 @@ xenParseSxpr(const struct sexpr *root,
"%s", _("domain information incomplete, missing name"));
goto error;
}
virUUIDParse(tmp, def->uuid);
if (virUUIDParse(tmp, def->uuid) < 0)
goto error;
if (sexpr_node_copy(root, "domain/description", &def->description) < 0)
goto no_memory;