If there are no parameters, there is nothing to validate.
If params == NULL, memcpy below results in memcpy(sorted, NULL, 0),
which is UB.
Found by UBSAN. Example of this codepath: virDomainBlockCopy()
(where nparams == 0 is valid) -> qemuDomainBlockCopy()
Signed-off-by: Oleg Vasilev <oleg.vasilev(a)virtuozzo.com>
---
src/util/virtypedparam.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c
index 3bb8b125e9..ef3b8052f6 100644
--- a/src/util/virtypedparam.c
+++ b/src/util/virtypedparam.c
@@ -68,6 +68,10 @@ virTypedParamsValidate(virTypedParameterPtr params, int nparams, ...)
g_autofree virTypedParameterPtr sorted = NULL;
g_autofree virTypedParameterPtr keys = NULL;
+ if (!nparams) {
+ return 0;
+ }
+
va_start(ap, nparams);
sorted = g_new0(virTypedParameter, nparams);
--
2.41.0