vici: Fix memory leaks if loading CA cert in authority section fails

The return value is now also fixed.  The reply allocation previously
prevented that sections with failed CA certs were rejected.

Also fixes two potential leaks if duplicate settings are sent by a VICI
client.

Fixes: 63d370387d ("vici: Certification Authority support added.")
This commit is contained in:
Tobias Brunner
2026-07-24 08:47:38 +02:00
parent 98fd5e9893
commit e03ec46466
+6 -4
View File
@@ -325,8 +325,8 @@ CALLBACK(parse_string, bool,
{
return FALSE;
}
free(*str);
*str = strndup(v.ptr, v.len);
return TRUE;
}
@@ -383,16 +383,18 @@ CALLBACK(parse_cacert, bool,
BUILD_BLOB_PEM, v, BUILD_END);
if (!cert)
{
return create_reply("parsing %N certificate failed",
certificate_type_names, CERT_X509);
return FALSE;
}
x509 = (x509_t*)cert;
if ((x509->get_flags(x509) & X509_CA) != X509_CA)
{
DBG1(DBG_CFG, "certificate in authority section lacks CA basic "
"constraint, rejected");
cert->destroy(cert);
return create_reply("certificate without CA flag, rejected");
return FALSE;
}
DESTROY_IF(*cacert);
*cacert = cert;
return TRUE;