[libvirt] [PATCH] conf: forbid negative values in virDomainParseScaledValue
by Martin Kletzander
It makes sense for none of the callers to have negative value as an
output and, fortunately, if anyone tried defining domain with negative
memory or any other value parsed by virDomainParseScaledValue(), the
resulting value was 0. That means we can error out during parsing as
it won't break anything.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1155843
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
"it won't break anything" -- famous last words?
src/conf/domain_conf.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 39befb0..a351382 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6334,28 +6334,34 @@ virDomainParseScaledValue(const char *xpath,
{
char *xpath_full = NULL;
char *unit = NULL;
+ char *bytes_str = NULL;
int ret = -1;
unsigned long long bytes;
*val = 0;
if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0)
goto cleanup;
- ret = virXPathULongLong(xpath_full, ctxt, &bytes);
- if (ret < 0) {
- if (ret == -2)
- virReportError(VIR_ERR_XML_ERROR,
- _("could not parse element %s"),
- xpath);
- else if (required)
+
+ bytes_str = virXPathString(xpath_full, ctxt);
+ if (!bytes_str) {
+ if (!required) {
+ ret = 0;
+ } else {
virReportError(VIR_ERR_XML_ERROR,
_("missing element %s"),
xpath);
- else
- ret = 0;
+ }
goto cleanup;
}
VIR_FREE(xpath_full);
+ if (virStrToLong_ullp(bytes_str, NULL, 10, &bytes) < 0) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Invalid value '%s' for element '%s'"),
+ bytes_str, xpath);
+ goto cleanup;
+ }
+
if (virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0)
goto cleanup;
unit = virXPathString(xpath_full, ctxt);
@@ -6366,6 +6372,7 @@ virDomainParseScaledValue(const char *xpath,
*val = bytes;
ret = 1;
cleanup:
+ VIR_FREE(bytes_str);
VIR_FREE(xpath_full);
VIR_FREE(unit);
return ret;
--
2.1.2
10 years
[libvirt] [PATCH] Fix memory leak in cmdNetworkDHCPLeases
by Luyao Huang
After use cidr_format in function virAsprintf and vshPrintExtra, need free
cidr_format.
Fix the following memory leak from valgrind, like:
18 bytes in 1 blocks are definitely lost in loss record 41 of 192
at 0x4C29BBD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
by 0x85CE36F: __vasprintf_chk (vasprintf_chk.c:80)
by 0x4EE52D5: UnknownInlinedFun (stdio2.h:210)
by 0x4EE52D5: virVasprintfInternal (virstring.c:459)
by 0x4EE53CA: virAsprintfInternal (virstring.c:480)
by 0x14FE96: cmdNetworkDHCPLeases (virsh-network.c:1378)
by 0x13006B: vshCommandRun (virsh.c:1915)
by 0x12A9E1: main (virsh.c:3699)
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
tools/virsh-network.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index 90392d3..8ff6fd8 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -1381,6 +1381,8 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
expirytime, EMPTYSTR(lease->mac),
EMPTYSTR(typestr), cidr_format,
EMPTYSTR(lease->hostname), EMPTYSTR(lease->clientid));
+
+ VIR_FREE(cidr_format);
}
ret = true;
--
1.8.3.1
10 years
[libvirt] [PATCH 1/2] virnetdev: stub virNetDev{Add, Del}Multi on FreeBSD
by Roman Bogorodskiy
Currently, build fails on FreeBSD because its struct ifreq does not
have ifr_hwaddr member. In order to fix that, check if this member
is present, otherwise fall back to the stub version of the
virNetDev{Add,Del}Multi functions.
---
configure.ac | 3 ++-
src/util/virnetdev.c | 6 ++++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index f7b02ff..31c5fa2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2694,7 +2694,8 @@ AC_SUBST([ws_plugindir])
# Check for Linux vs. BSD ifreq members
AC_CHECK_MEMBERS([struct ifreq.ifr_newname,
struct ifreq.ifr_ifindex,
- struct ifreq.ifr_index],
+ struct ifreq.ifr_index,
+ struct ifreq.ifr_hwaddr],
[], [],
[#include <sys/socket.h>
#include <net/if.h>
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 127bfb2..ac82a74 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -1971,7 +1971,8 @@ virNetDevGetLinkInfo(const char *ifname,
#endif /* defined(__linux__) */
-#if defined(SIOCADDMULTI) && defined(HAVE_STRUCT_IFREQ)
+#if defined(SIOCADDMULTI) && defined(HAVE_STRUCT_IFREQ) && \
+ defined(HAVE_STRUCT_IFREQ_IFR_HWADDR)
/**
* virNetDevAddMulti:
* @ifname: interface name to which to add multicast MAC address
@@ -2019,7 +2020,8 @@ int virNetDevAddMulti(const char *ifname ATTRIBUTE_UNUSED,
}
#endif
-#if defined(SIOCDELMULTI) && defined(HAVE_STRUCT_IFREQ)
+#if defined(SIOCDELMULTI) && defined(HAVE_STRUCT_IFREQ) && \
+ defined(HAVE_STRUCT_IFREQ_IFR_HWADDR)
/**
* virNetDevDelMulti:
* @ifname: interface name from which to delete the multicast MAC address
--
2.0.2
10 years
[libvirt] [PATCH] virnetdev: Resolve some Coverity issues
by John Ferlan
Coverity discovered a few issues with recent changes in this module
from commit id 'cc0e8c24'. This patches fixes those.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/util/virnetdev.c | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 127bfb2..8bd1af4 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -59,15 +59,20 @@ VIR_LOG_INIT("util.netdev");
#define PROC_NET_DEV_MCAST "/proc/net/dev_mcast"
#define MAX_MCAST_SIZE 50*14336
#define VIR_MCAST_NAME_LEN (IFNAMSIZ + 1)
-#define VIR_MCAST_INDEX_TOKEN_IDX 0
-#define VIR_MCAST_NAME_TOKEN_IDX 1
-#define VIR_MCAST_USERS_TOKEN_IDX 2
-#define VIR_MCAST_GLOBAL_TOKEN_IDX 3
-#define VIR_MCAST_ADDR_TOKEN_IDX 4
#define VIR_MCAST_NUM_TOKENS 5
#define VIR_MCAST_TOKEN_DELIMS " \n"
#define VIR_MCAST_ADDR_LEN (VIR_MAC_HEXLEN + 1)
+typedef enum {
+ VIR_MCAST_TYPE_INDEX_TOKEN,
+ VIR_MCAST_TYPE_NAME_TOKEN,
+ VIR_MCAST_TYPE_USERS_TOKEN,
+ VIR_MCAST_TYPE_GLOBAL_TOKEN,
+ VIR_MCAST_TYPE_ADDR_TOKEN,
+
+ VIR_MCAST_TYPE_LAST
+} virMCastType;
+
typedef struct _virNetDevMcastEntry virNetDevMcastEntry;
typedef virNetDevMcastEntry *virNetDevMcastEntryPtr;
struct _virNetDevMcastEntry {
@@ -2076,7 +2081,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
char *saveptr;
char *endptr;
- for (ifindex = 0, next = buf; ifindex < VIR_MCAST_NUM_TOKENS; ifindex++,
+ for (ifindex = 0, next = buf; ifindex < VIR_MCAST_TYPE_LAST; ifindex++,
next = NULL) {
token = strtok_r(next, VIR_MCAST_TOKEN_DELIMS, &saveptr);
@@ -2087,8 +2092,8 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
return -1;
}
- switch (ifindex) {
- case VIR_MCAST_INDEX_TOKEN_IDX:
+ switch ((virMCastType)ifindex) {
+ case VIR_MCAST_TYPE_INDEX_TOKEN:
if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
virReportSystemError(EINVAL,
_("Failed to parse interface index from '%s'"),
@@ -2098,7 +2103,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
}
mcast->index = num;
break;
- case VIR_MCAST_NAME_TOKEN_IDX:
+ case VIR_MCAST_TYPE_NAME_TOKEN:
if (virStrncpy(mcast->name, token, strlen(token),
VIR_MCAST_NAME_LEN) == NULL) {
virReportSystemError(EINVAL,
@@ -2107,7 +2112,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
return -1;
}
break;
- case VIR_MCAST_USERS_TOKEN_IDX:
+ case VIR_MCAST_TYPE_USERS_TOKEN:
if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
virReportSystemError(EINVAL,
_("Failed to parse users from '%s'"),
@@ -2117,7 +2122,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
}
mcast->users = num;
break;
- case VIR_MCAST_GLOBAL_TOKEN_IDX:
+ case VIR_MCAST_TYPE_GLOBAL_TOKEN:
if (virStrToLong_i(token, &endptr, 10, &num) < 0) {
virReportSystemError(EINVAL,
_("Failed to parse users from '%s'"),
@@ -2127,7 +2132,7 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
}
mcast->global = num;
break;
- case VIR_MCAST_ADDR_TOKEN_IDX:
+ case VIR_MCAST_TYPE_ADDR_TOKEN:
if (virMacAddrParseHex((const char*)token,
&mcast->macaddr) < 0) {
virReportSystemError(EINVAL,
@@ -2135,7 +2140,9 @@ static int virNetDevParseMcast(char *buf, virNetDevMcastEntryPtr mcast)
buf);
}
break;
- default:
+
+ /* coverity[dead_error_begin] */
+ case VIR_MCAST_TYPE_LAST:
break;
}
}
@@ -2194,9 +2201,7 @@ static int virNetDevGetMcastList(const char *ifname,
ret = 0;
cleanup:
- if (ret < 0)
- virNetDevMcastListClear(mcast);
-
+ VIR_FREE(buf);
VIR_FREE(entry);
return ret;
--
1.9.3
10 years
[libvirt] [PATCHv2 0/2] Extend NIC_RX_FILTER_CHANGED event handler to process multicast list
by akrowiak@linux.vnet.ibm.com
From: Tony Krowiak <akrowiak(a)linux.vnet.ibm.com>
This patch set extends the handler for qemu's NIC_RX_FILTER_CHANGED event. It adds
code to compare the old and new multicast MAC address lists and programs the
macvtap filters to match the guest.
Changes from V1:
Responded to review comments from Laine Stump and Eric Blake
Tony Krowiak (2):
util: Functions to update host network device's multicast filter
qemu: change macvtap multicast list in response to
NIC_RX_FILTER_CHANGED
10 years
[libvirt] [PATCH] qemu: better error message when block job can't succeed
by Eric Blake
https://bugzilla.redhat.com/show_bug.cgi?id=1140981 reports that
the qemu-kvm shipped as part of RHEL 7.0 intentionally cripples
block jobs by removing the 'block-stream' QMP command, but that
our probe for whether block jobs work was merely whether
'block-job-cancel' exists. Meanwhile, older qemu spelled the
two commands block_stream and block_job_cancel. We know of no
qemu build that has block-stream while lacking block-job-cancel,
so it is easiest to change our witness to the command that
starts a job rather than ends one. On RHEL, this results in
changing the message from an ugly:
error: Requested operation is not valid: Command 'block-stream' is not found
to a nicer:
error: unsupported configuration: block jobs not supported with this qemu binary
* src/qemu/qemu_capabilities.h (QEMU_CAPS_BLOCKJOB_SYNC): Tweak comment.
* src/qemu/qemu_capabilities.c (virQEMUCapsCommands): Look for stream
rather than cancel when determining the flavor of block jobs supported.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 4 ++--
src/qemu/qemu_capabilities.h | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 6fcb5c7..b6c0f1b 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1422,8 +1422,8 @@ struct virQEMUCapsStringFlags {
struct virQEMUCapsStringFlags virQEMUCapsCommands[] = {
{ "system_wakeup", QEMU_CAPS_WAKEUP },
{ "transaction", QEMU_CAPS_TRANSACTION },
- { "block_job_cancel", QEMU_CAPS_BLOCKJOB_SYNC },
- { "block-job-cancel", QEMU_CAPS_BLOCKJOB_ASYNC },
+ { "block_stream", QEMU_CAPS_BLOCKJOB_SYNC },
+ { "block-stream", QEMU_CAPS_BLOCKJOB_ASYNC },
{ "dump-guest-memory", QEMU_CAPS_DUMP_GUEST_MEMORY },
{ "query-spice", QEMU_CAPS_SPICE },
{ "query-kvm", QEMU_CAPS_KVM },
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 0214f30..c0e2172 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -127,8 +127,8 @@ typedef enum {
QEMU_CAPS_SCSI_DISK_CHANNEL = 87, /* Is scsi-disk.channel available? */
QEMU_CAPS_SCSI_BLOCK = 88, /* -device scsi-block */
QEMU_CAPS_TRANSACTION = 89, /* transaction monitor command */
- QEMU_CAPS_BLOCKJOB_SYNC = 90, /* RHEL 6.2 block_job_cancel */
- QEMU_CAPS_BLOCKJOB_ASYNC = 91, /* qemu 1.1 block-job-cancel */
+ QEMU_CAPS_BLOCKJOB_SYNC = 90, /* old block_job_cancel, block_stream */
+ QEMU_CAPS_BLOCKJOB_ASYNC = 91, /* new block-job-cancel, block-stream */
QEMU_CAPS_SCSI_CD = 92, /* -device scsi-cd */
QEMU_CAPS_IDE_CD = 93, /* -device ide-cd */
QEMU_CAPS_NO_USER_CONFIG = 94, /* -no-user-config */
--
1.9.3
10 years
Re: [libvirt] Entering freeze and release of cadidate release 1 of 1.2.10
by Conrad Meyer
Hi all,
The recent commit with SHA1 cc0e8c244d080f56392278e836cc378ba848e7aa,
"util: Functions to update host network device's multicast filter,"
breaks the build on FreeBSD, so please address this before 1.2.10
release.
Here is the output from Clang:
CC util/libvirt_util_la-virnetdev.lo
util/virnetdev.c:1995:9: error: no member named 'ifr_hwaddr' in 'struct ifreq'
ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
~~~ ^
util/virnetdev.c:1996:52: error: no member named 'ifr_hwaddr' in 'struct ifreq'
virMacAddrGetRaw(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data);
~~~ ^
util/virnetdev.c:2043:9: error: no member named 'ifr_hwaddr' in 'struct ifreq'
ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
~~~ ^
util/virnetdev.c:2044:52: error: no member named 'ifr_hwaddr' in 'struct ifreq'
virMacAddrGetRaw(macaddr, (unsigned char *)ifr.ifr_hwaddr.sa_data);
~~~ ^
4 errors generated.
Thanks,
Conrad
10 years
[libvirt] [PATCH for 1.2.10 0/2] Fix crash when parsing backing chain URI with transport
by Peter Krempa
See patch 1 for explanation.
Peter Krempa (2):
storage: Fix crash when parsing backing store URI with schema
test: Add test to verify helpers used for backing file name parsing
src/util/virstoragefile.c | 10 +++++-----
tests/virstoragetest.c | 31 +++++++++++++++++++++++++------
tests/virstringtest.c | 3 +++
tests/viruritest.c | 1 +
4 files changed, 34 insertions(+), 11 deletions(-)
--
2.1.0
10 years
[libvirt] [PATCH 0/7] static zero initialization
by Eric Blake
Based on a comment I just made while reviewing Dan's patches,
we might as well adopt a consistent style of relying on the
C guarantee that static variables are automatically
zero-initialized without any effort on our part.
Eric Blake (7):
audit: use bool for audit log choice
maint: avoid static zero init in core files
maint: avoid static zero init in tools
maint: avoid static zero init in tests
maint: avoid static zero init in helpers
maint: avoid static zero init in drivers
maint: add syntax check to prohibit static zero init
cfg.mk | 8 ++++++++
daemon/libvirtd.c | 2 +-
src/conf/nwfilter_conf.c | 2 +-
src/cpu/cpu_x86.c | 2 +-
src/interface/interface_backend_netcf.c | 2 +-
src/libvirt.c | 18 +++++++++---------
src/libxl/libxl_driver.c | 2 +-
src/locking/lock_daemon.c | 2 +-
src/locking/lock_driver_lockd.c | 4 ++--
src/locking/lock_driver_sanlock.c | 2 +-
src/lxc/lxc_controller.c | 2 +-
src/network/bridge_driver.c | 2 +-
src/node_device/node_device_udev.c | 2 +-
src/nwfilter/nwfilter_learnipaddr.c | 2 +-
src/openvz/openvz_util.c | 4 ++--
src/phyp/phyp_driver.c | 8 +++++---
src/qemu/qemu_driver.c | 5 +++--
src/remote/remote_driver.c | 2 +-
src/rpc/virnetserver.c | 4 ++--
src/security/security_selinux.c | 2 +-
src/test/test_driver.c | 2 +-
src/uml/uml_driver.c | 2 +-
src/util/viralloc.c | 10 +++++-----
src/util/viraudit.c | 4 ++--
src/util/viraudit.h | 4 ++--
src/util/virdbus.c | 4 ++--
src/util/virevent.c | 14 +++++++-------
src/util/virfile.c | 2 +-
src/util/virlog.c | 16 ++++++++--------
src/util/virnetlink.c | 2 +-
src/util/virprocess.c | 3 +--
src/util/virthread.h | 4 ++--
src/vbox/vbox_XPCOMCGlue.c | 4 ++--
src/vbox/vbox_tmpl.c | 2 +-
src/xen/xen_driver.c | 4 ++--
src/xen/xen_hypervisor.c | 4 ++--
tests/eventtest.c | 6 +++---
tests/testutils.c | 12 ++++++------
tests/virhostdevtest.c | 2 +-
tests/virportallocatortest.c | 2 +-
tests/virscsitest.c | 2 +-
tools/virsh-console.c | 5 +----
tools/virsh-domain.c | 2 +-
tools/virsh.c | 4 ++--
tools/virt-host-validate-common.c | 4 ++--
45 files changed, 102 insertions(+), 95 deletions(-)
--
1.9.3
10 years