mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
Annotate many methods with ATTRIBUTE_RETURN_CHECK & fix problems
Nearly all of the methods in src/util/util.h have error codes that must be checked by the caller to correct detect & report failure. Add ATTRIBUTE_RETURN_CHECK to ensure compile time validation of this * daemon/libvirtd.c: Add explicit check on return value of virAsprintf * src/conf/domain_conf.c: Add missing check on virParseMacAddr return value status & report error * src/network/bridge_driver.c: Add missing OOM check on virAsprintf and report error * src/qemu/qemu_conf.c: Add missing check on virParseMacAddr return value status & report error * src/security/security_selinux.c: Remove call to virRandomInitialize that's done in libvirt.c already * src/storage/storage_backend_logical.c: Add check & log on virRun return status * src/util/util.c: Add missing checks on virAsprintf/Run status * src/util/util.h: Annotate all methods with ATTRIBUTE_RETURN_CHECK if they return an error status code * src/vbox/vbox_tmpl.c: Add missing check on virParseMacAddr * src/xen/xm_internal.c: Add missing checks on virAsprintf * tests/qemuargv2xmltest.c: Remove bogus call to virRandomInitialize()
This commit is contained in:
parent
3505790b85
commit
46992453b9
@ -752,13 +752,16 @@ static int qemudInitPaths(struct qemud_server *server,
|
|||||||
goto snprintf_error;
|
goto snprintf_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server->privileged)
|
if (server->privileged) {
|
||||||
server->logDir = strdup (LOCAL_STATE_DIR "/log/libvirt");
|
if (!(server->logDir = strdup (LOCAL_STATE_DIR "/log/libvirt")))
|
||||||
else
|
virReportOOMError(NULL);
|
||||||
virAsprintf(&server->logDir, "%s/.libvirt/log", dir_prefix);
|
} else {
|
||||||
|
if (virAsprintf(&server->logDir, "%s/.libvirt/log", dir_prefix) < 0)
|
||||||
|
virReportOOMError(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
if (server->logDir == NULL)
|
if (server->logDir == NULL)
|
||||||
virReportOOMError(NULL);
|
goto cleanup;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
@ -1109,7 +1109,12 @@ virDomainNetDefParseXML(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (macaddr) {
|
if (macaddr) {
|
||||||
virParseMacAddr((const char *)macaddr, def->mac);
|
if (virParseMacAddr((const char *)macaddr, def->mac) < 0) {
|
||||||
|
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("unable to parse mac address '%s'"),
|
||||||
|
(const char *)macaddr);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
virCapabilitiesGenerateMac(caps, def->mac);
|
virCapabilitiesGenerateMac(caps, def->mac);
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,10 @@ networkFindActiveConfigs(struct network_driver *driver) {
|
|||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
char *pidpath;
|
char *pidpath;
|
||||||
|
|
||||||
virAsprintf(&pidpath, "/proc/%d/exe", obj->dnsmasqPid);
|
if (virAsprintf(&pidpath, "/proc/%d/exe", obj->dnsmasqPid) < 0) {
|
||||||
|
virReportOOMError(NULL);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
if (virFileLinkPointsTo(pidpath, DNSMASQ) == 0)
|
if (virFileLinkPointsTo(pidpath, DNSMASQ) == 0)
|
||||||
obj->dnsmasqPid = -1;
|
obj->dnsmasqPid = -1;
|
||||||
VIR_FREE(pidpath);
|
VIR_FREE(pidpath);
|
||||||
@ -157,6 +160,7 @@ networkFindActiveConfigs(struct network_driver *driver) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
virNetworkObjUnlock(obj);
|
virNetworkObjUnlock(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2841,7 +2841,14 @@ qemuParseCommandLineNet(virConnectPtr conn,
|
|||||||
for (i = 0 ; i < nkeywords ; i++) {
|
for (i = 0 ; i < nkeywords ; i++) {
|
||||||
if (STREQ(keywords[i], "macaddr")) {
|
if (STREQ(keywords[i], "macaddr")) {
|
||||||
genmac = 0;
|
genmac = 0;
|
||||||
virParseMacAddr(values[i], def->mac);
|
if (virParseMacAddr(values[i], def->mac) < 0) {
|
||||||
|
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("unable to parse mac address '%s'"),
|
||||||
|
values[i]);
|
||||||
|
virDomainNetDefFree(def);
|
||||||
|
def = NULL;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
} else if (STREQ(keywords[i], "model")) {
|
} else if (STREQ(keywords[i], "model")) {
|
||||||
def->model = values[i];
|
def->model = values[i];
|
||||||
values[i] = NULL;
|
values[i] = NULL;
|
||||||
|
@ -108,8 +108,6 @@ SELinuxInitialize(virConnectPtr conn)
|
|||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
int fd = 0;
|
int fd = 0;
|
||||||
|
|
||||||
virRandomInitialize(time(NULL) ^ getpid());
|
|
||||||
|
|
||||||
fd = open(selinux_virtual_domain_context_path(), O_RDONLY);
|
fd = open(selinux_virtual_domain_context_path(), O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
virReportSystemError(conn, errno,
|
virReportSystemError(conn, errno,
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "storage_conf.h"
|
#include "storage_conf.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "logging.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
|
|
||||||
@ -336,7 +337,9 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn,
|
|||||||
* that might be hanging around, so if this fails for some reason, the
|
* that might be hanging around, so if this fails for some reason, the
|
||||||
* worst that happens is that scanning doesn't pick everything up
|
* worst that happens is that scanning doesn't pick everything up
|
||||||
*/
|
*/
|
||||||
virRun(conn, scanprog, &exitstatus);
|
if (virRun(conn, scanprog, &exitstatus) < 0) {
|
||||||
|
VIR_WARN0("Failure when running vgscan to refresh physical volumes");
|
||||||
|
}
|
||||||
|
|
||||||
memset(&sourceList, 0, sizeof(sourceList));
|
memset(&sourceList, 0, sizeof(sourceList));
|
||||||
sourceList.type = VIR_STORAGE_POOL_LOGICAL;
|
sourceList.type = VIR_STORAGE_POOL_LOGICAL;
|
||||||
|
@ -1257,7 +1257,8 @@ int virFileOpenTtyAt(const char *ptmx ATTRIBUTE_UNUSED,
|
|||||||
char* virFilePid(const char *dir, const char* name)
|
char* virFilePid(const char *dir, const char* name)
|
||||||
{
|
{
|
||||||
char *pidfile;
|
char *pidfile;
|
||||||
virAsprintf(&pidfile, "%s/%s.pid", dir, name);
|
if (virAsprintf(&pidfile, "%s/%s.pid", dir, name) < 0)
|
||||||
|
return NULL;
|
||||||
return pidfile;
|
return pidfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2108,7 +2109,8 @@ void virFileWaitForDevices(virConnectPtr conn)
|
|||||||
* If this fails for any reason, we still have the backup of polling for
|
* If this fails for any reason, we still have the backup of polling for
|
||||||
* 5 seconds for device nodes.
|
* 5 seconds for device nodes.
|
||||||
*/
|
*/
|
||||||
virRun(conn, settleprog, &exitstatus);
|
if (virRun(conn, settleprog, &exitstatus) < 0)
|
||||||
|
{}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void virFileWaitForDevices(virConnectPtr conn ATTRIBUTE_UNUSED) {}
|
void virFileWaitForDevices(virConnectPtr conn ATTRIBUTE_UNUSED) {}
|
||||||
|
@ -41,8 +41,8 @@ enum {
|
|||||||
VIR_EXEC_CLEAR_CAPS = (1 << 2),
|
VIR_EXEC_CLEAR_CAPS = (1 << 2),
|
||||||
};
|
};
|
||||||
|
|
||||||
int virSetNonBlock(int fd);
|
int virSetNonBlock(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virSetCloseExec(int fd);
|
int virSetCloseExec(int fd) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
/* This will execute in the context of the first child
|
/* This will execute in the context of the first child
|
||||||
* after fork() but before execve() */
|
* after fork() but before execve() */
|
||||||
@ -57,7 +57,7 @@ int virExecDaemonize(virConnectPtr conn,
|
|||||||
int flags,
|
int flags,
|
||||||
virExecHook hook,
|
virExecHook hook,
|
||||||
void *data,
|
void *data,
|
||||||
char *pidfile);
|
char *pidfile) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virExecWithHook(virConnectPtr conn,
|
int virExecWithHook(virConnectPtr conn,
|
||||||
const char *const*argv,
|
const char *const*argv,
|
||||||
const char *const*envp,
|
const char *const*envp,
|
||||||
@ -69,7 +69,7 @@ int virExecWithHook(virConnectPtr conn,
|
|||||||
int flags,
|
int flags,
|
||||||
virExecHook hook,
|
virExecHook hook,
|
||||||
void *data,
|
void *data,
|
||||||
char *pidfile);
|
char *pidfile) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virExec(virConnectPtr conn,
|
int virExec(virConnectPtr conn,
|
||||||
const char *const*argv,
|
const char *const*argv,
|
||||||
const char *const*envp,
|
const char *const*envp,
|
||||||
@ -78,14 +78,14 @@ int virExec(virConnectPtr conn,
|
|||||||
int infd,
|
int infd,
|
||||||
int *outfd,
|
int *outfd,
|
||||||
int *errfd,
|
int *errfd,
|
||||||
int flags);
|
int flags) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virRun(virConnectPtr conn, const char *const*argv, int *status);
|
int virRun(virConnectPtr conn, const char *const*argv, int *status) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
int virFileReadLimFD(int fd, int maxlen, char **buf);
|
int virFileReadLimFD(int fd, int maxlen, char **buf) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
int virFileReadAll(const char *path, int maxlen, char **buf);
|
int virFileReadAll(const char *path, int maxlen, char **buf) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
int virFileWriteStr(const char *path, const char *str);
|
int virFileWriteStr(const char *path, const char *str) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
int virFileMatchesNameSuffix(const char *file,
|
int virFileMatchesNameSuffix(const char *file,
|
||||||
const char *name,
|
const char *name,
|
||||||
@ -95,28 +95,28 @@ int virFileHasSuffix(const char *str,
|
|||||||
const char *suffix);
|
const char *suffix);
|
||||||
|
|
||||||
int virFileStripSuffix(char *str,
|
int virFileStripSuffix(char *str,
|
||||||
const char *suffix);
|
const char *suffix) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
int virFileLinkPointsTo(const char *checkLink,
|
int virFileLinkPointsTo(const char *checkLink,
|
||||||
const char *checkDest);
|
const char *checkDest);
|
||||||
|
|
||||||
int virFileResolveLink(const char *linkpath,
|
int virFileResolveLink(const char *linkpath,
|
||||||
char **resultpath);
|
char **resultpath) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
char *virFindFileInPath(const char *file);
|
char *virFindFileInPath(const char *file);
|
||||||
|
|
||||||
int virFileExists(const char *path);
|
int virFileExists(const char *path);
|
||||||
|
|
||||||
int virFileMakePath(const char *path);
|
int virFileMakePath(const char *path) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
int virFileBuildPath(const char *dir,
|
int virFileBuildPath(const char *dir,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *ext,
|
const char *ext,
|
||||||
char *buf,
|
char *buf,
|
||||||
unsigned int buflen);
|
unsigned int buflen) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
int virFileAbsPath(const char *path,
|
int virFileAbsPath(const char *path,
|
||||||
char **abspath);
|
char **abspath) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
int virFileOpenTty(int *ttymaster,
|
int virFileOpenTty(int *ttymaster,
|
||||||
char **ttyName,
|
char **ttyName,
|
||||||
@ -129,13 +129,13 @@ int virFileOpenTtyAt(const char *ptmx,
|
|||||||
char* virFilePid(const char *dir,
|
char* virFilePid(const char *dir,
|
||||||
const char *name);
|
const char *name);
|
||||||
int virFileWritePidPath(const char *path,
|
int virFileWritePidPath(const char *path,
|
||||||
pid_t pid);
|
pid_t pid) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virFileWritePid(const char *dir,
|
int virFileWritePid(const char *dir,
|
||||||
const char *name,
|
const char *name,
|
||||||
pid_t pid);
|
pid_t pid) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virFileReadPid(const char *dir,
|
int virFileReadPid(const char *dir,
|
||||||
const char *name,
|
const char *name,
|
||||||
pid_t *pid);
|
pid_t *pid) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virFileDeletePid(const char *dir,
|
int virFileDeletePid(const char *dir,
|
||||||
const char *name);
|
const char *name);
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ int virMacAddrCompare (const char *mac1, const char *mac2);
|
|||||||
void virSkipSpaces(const char **str);
|
void virSkipSpaces(const char **str);
|
||||||
int virParseNumber(const char **str);
|
int virParseNumber(const char **str);
|
||||||
int virAsprintf(char **strp, const char *fmt, ...)
|
int virAsprintf(char **strp, const char *fmt, ...)
|
||||||
ATTRIBUTE_FMT_PRINTF(2, 3);
|
ATTRIBUTE_FMT_PRINTF(2, 3) ATTRIBUTE_RETURN_CHECK;
|
||||||
char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
|
char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes)
|
||||||
ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_RETURN_CHECK;
|
||||||
char *virStrcpy(char *dest, const char *src, size_t destbytes)
|
char *virStrcpy(char *dest, const char *src, size_t destbytes)
|
||||||
@ -179,7 +179,7 @@ char *virStrcpy(char *dest, const char *src, size_t destbytes)
|
|||||||
#define VIR_MAC_STRING_BUFLEN VIR_MAC_BUFLEN * 3
|
#define VIR_MAC_STRING_BUFLEN VIR_MAC_BUFLEN * 3
|
||||||
|
|
||||||
int virParseMacAddr(const char* str,
|
int virParseMacAddr(const char* str,
|
||||||
unsigned char *addr);
|
unsigned char *addr) ATTRIBUTE_RETURN_CHECK;
|
||||||
void virFormatMacAddr(const unsigned char *addr,
|
void virFormatMacAddr(const unsigned char *addr,
|
||||||
char *str);
|
char *str);
|
||||||
void virGenerateMacAddr(const unsigned char *prefix,
|
void virGenerateMacAddr(const unsigned char *prefix,
|
||||||
@ -233,13 +233,13 @@ char *virGetUserName(virConnectPtr conn,
|
|||||||
uid_t uid);
|
uid_t uid);
|
||||||
int virGetUserID(virConnectPtr conn,
|
int virGetUserID(virConnectPtr conn,
|
||||||
const char *name,
|
const char *name,
|
||||||
uid_t *uid);
|
uid_t *uid) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virGetGroupID(virConnectPtr conn,
|
int virGetGroupID(virConnectPtr conn,
|
||||||
const char *name,
|
const char *name,
|
||||||
gid_t *gid);
|
gid_t *gid) ATTRIBUTE_RETURN_CHECK;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int virRandomInitialize(unsigned int seed);
|
int virRandomInitialize(unsigned int seed) ATTRIBUTE_RETURN_CHECK;
|
||||||
int virRandom(int max);
|
int virRandom(int max);
|
||||||
|
|
||||||
#ifdef HAVE_MNTENT_H
|
#ifdef HAVE_MNTENT_H
|
||||||
|
@ -2219,7 +2219,9 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
|
|||||||
MACAddress[4], MACAddress[5], MACAddress[6], MACAddress[7],
|
MACAddress[4], MACAddress[5], MACAddress[6], MACAddress[7],
|
||||||
MACAddress[8], MACAddress[9], MACAddress[10], MACAddress[11]);
|
MACAddress[8], MACAddress[9], MACAddress[10], MACAddress[11]);
|
||||||
|
|
||||||
virParseMacAddr(macaddr, def->nets[netAdpIncCnt]->mac);
|
/* XXX some real error handling here some day ... */
|
||||||
|
if (virParseMacAddr(macaddr, def->nets[netAdpIncCnt]->mac) < 0)
|
||||||
|
{}
|
||||||
|
|
||||||
netAdpIncCnt++;
|
netAdpIncCnt++;
|
||||||
|
|
||||||
|
@ -3035,14 +3035,16 @@ xenXMDomainBlockPeek (virDomainPtr dom,
|
|||||||
static char *xenXMAutostartLinkName(virDomainPtr dom)
|
static char *xenXMAutostartLinkName(virDomainPtr dom)
|
||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
virAsprintf(&ret, "/etc/xen/auto/%s", dom->name);
|
if (virAsprintf(&ret, "/etc/xen/auto/%s", dom->name) < 0)
|
||||||
|
return NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *xenXMDomainConfigName(virDomainPtr dom)
|
static char *xenXMDomainConfigName(virDomainPtr dom)
|
||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
virAsprintf(&ret, "/etc/xen/%s", dom->name);
|
if (virAsprintf(&ret, "/etc/xen/%s", dom->name) < 0)
|
||||||
|
return NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,8 +109,6 @@ mymain(int argc, char **argv)
|
|||||||
if (!abs_srcdir)
|
if (!abs_srcdir)
|
||||||
abs_srcdir = getcwd(cwd, sizeof(cwd));
|
abs_srcdir = getcwd(cwd, sizeof(cwd));
|
||||||
|
|
||||||
virRandomInitialize(0);
|
|
||||||
|
|
||||||
if ((driver.caps = testQemuCapsInit()) == NULL)
|
if ((driver.caps = testQemuCapsInit()) == NULL)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
if((driver.stateDir = strdup("/nowhere")) == NULL)
|
if((driver.stateDir = strdup("/nowhere")) == NULL)
|
||||||
|
Loading…
Reference in New Issue
Block a user