]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: don't validate empty params
authorOleg Vasilev <oleg.vasilev@virtuozzo.com>
Fri, 23 Jun 2023 09:20:50 +0000 (15:20 +0600)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 26 Jun 2023 12:19:18 +0000 (14:19 +0200)
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@virtuozzo.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
src/util/virtypedparam.c

index 3bb8b125e956d97cc29ac97c21eda15491b56164..ef3b8052f6b5315c7e9096d2b3c6c445b9734035 100644 (file)
@@ -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);