Improve invalid argument checks in the size query case. The drivers already
relied on this unchecked behavior.
Relax the implementation of virDomainGet(Memory|Blkio)MemoryParameters
in the drivers and allow to pass more memory than necessary for all
parameters.
---
src/libvirt.c | 13 ++++++++-----
src/lxc/lxc_driver.c | 5 +++--
src/qemu/qemu_driver.c | 5 +++--
3 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/src/libvirt.c b/src/libvirt.c
index 3b41f1d..d6e222e 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3051,7 +3051,7 @@ error:
* @nparams: pointer to number of memory parameters
* @flags: currently unused, for future extension
*
- * Get the memory parameters, the @params array will be filled with the values
+ * Get all memory parameters, the @params array will be filled with the values
* equal to the number of parameters suggested by @nparams
*
* As the value of @nparams is dynamic, call the API setting @nparams to 0 and
@@ -3094,7 +3094,8 @@ virDomainGetMemoryParameters(virDomainPtr domain,
virDispatchError(NULL);
return -1;
}
- if ((nparams == NULL) || (*nparams < 0)) {
+ if ((nparams == NULL) || (*nparams < 0) ||
+ (params == NULL && *nparams != 0)) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
@@ -3177,8 +3178,9 @@ error:
* @nparams: pointer to number of blkio parameters
* @flags: currently unused, for future extension
*
- * Get the blkio parameters, the @params array will be filled with the values
- * equal to the number of parameters suggested by @nparams
+ * Get all blkio parameters, the @params array will be filled with the values
+ * equal to the number of parameters suggested by @nparams.
+ * See virDomainGetMemoryParameters for an equivalent usage example.
*
* This function requires privileged access to the hypervisor. This function
* expects the caller to allocate the @params.
@@ -3202,7 +3204,8 @@ virDomainGetBlkioParameters(virDomainPtr domain,
virDispatchError(NULL);
return -1;
}
- if ((nparams == NULL) || (*nparams < 0)) {
+ if ((nparams == NULL) || (*nparams < 0) ||
+ (params == NULL && *nparams != 0)) {
virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index a65299b..9e09c95 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -871,7 +871,7 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
ret = 0;
goto cleanup;
}
- if ((*nparams) != LXC_NB_MEM_PARAM) {
+ if ((*nparams) < LXC_NB_MEM_PARAM) {
lxcError(VIR_ERR_INVALID_ARG,
"%s", _("Invalid parameter count"));
goto cleanup;
@@ -883,7 +883,7 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
goto cleanup;
}
- for (i = 0; i < *nparams; i++) {
+ for (i = 0; i < LXC_NB_MEM_PARAM; i++) {
virMemoryParameterPtr param = ¶ms[i];
val = 0;
param->value.ul = 0;
@@ -941,6 +941,7 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
}
}
+ *nparams = LXC_NB_MEM_PARAM;
ret = 0;
cleanup:
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9a7286d..2f9c8e7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4957,7 +4957,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
goto cleanup;
}
- if ((*nparams) != QEMU_NB_MEM_PARAM) {
+ if ((*nparams) < QEMU_NB_MEM_PARAM) {
qemuReportError(VIR_ERR_INVALID_ARG,
"%s", _("Invalid parameter count"));
goto cleanup;
@@ -4969,7 +4969,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
goto cleanup;
}
- for (i = 0; i < *nparams; i++) {
+ for (i = 0; i < QEMU_NB_MEM_PARAM; i++) {
virMemoryParameterPtr param = ¶ms[i];
val = 0;
param->value.ul = 0;
@@ -5027,6 +5027,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
}
}
+ *nparams = QEMU_NB_MEM_PARAM;
ret = 0;
cleanup:
--
1.7.0.4