From 7b793a00bddd34c56393e1dbaa7dc85700059c55 Mon Sep 17 00:00:00 2001 From: Oleg Vasilev Date: Fri, 23 Jun 2023 15:20:50 +0600 Subject: [PATCH] util: don't validate empty params 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 Reviewed-by: Kristina Hanicova --- 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);