mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
virnettlscontext: Resolve Coverity warnings (UNINIT)
Coverity complained about the usage of the uninitialized cacerts in the event(s) that "access(certFile, R_OK)" and/or "access(cacertFile, R_OK)" fail the for loop used to fill in the certs will have indeterminate data as well as the possibility that both failures would result in the gnutls_x509_crt_deinit() call having a similar fate. Initializing cacerts only would resolve the issue; however, it still would leave the indeterminate action, so rather add a parameter to the virNetTLSContextLoadCACertListFromFile() to pass the max size rather then overloading the returned count parameter. If the the call is never made, then we won't go through the for loops referencing the empty cacerts
This commit is contained in:
parent
6ff0cffd55
commit
f905cc9984
@ -545,12 +545,12 @@ cleanup:
|
|||||||
|
|
||||||
static int virNetTLSContextLoadCACertListFromFile(const char *certFile,
|
static int virNetTLSContextLoadCACertListFromFile(const char *certFile,
|
||||||
gnutls_x509_crt_t *certs,
|
gnutls_x509_crt_t *certs,
|
||||||
|
unsigned int certMax,
|
||||||
size_t *ncerts)
|
size_t *ncerts)
|
||||||
{
|
{
|
||||||
gnutls_datum_t data;
|
gnutls_datum_t data;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
unsigned int certMax = *ncerts;
|
|
||||||
|
|
||||||
*ncerts = 0;
|
*ncerts = 0;
|
||||||
VIR_DEBUG("certFile %s", certFile);
|
VIR_DEBUG("certFile %s", certFile);
|
||||||
@ -584,15 +584,17 @@ static int virNetTLSContextSanityCheckCredentials(bool isServer,
|
|||||||
{
|
{
|
||||||
gnutls_x509_crt_t cert = NULL;
|
gnutls_x509_crt_t cert = NULL;
|
||||||
gnutls_x509_crt_t cacerts[MAX_CERTS];
|
gnutls_x509_crt_t cacerts[MAX_CERTS];
|
||||||
size_t ncacerts = MAX_CERTS;
|
size_t ncacerts = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
|
memset(cacerts, 0, sizeof(cacerts));
|
||||||
if ((access(certFile, R_OK) == 0) &&
|
if ((access(certFile, R_OK) == 0) &&
|
||||||
!(cert = virNetTLSContextLoadCertFromFile(certFile, isServer)))
|
!(cert = virNetTLSContextLoadCertFromFile(certFile, isServer)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
if ((access(cacertFile, R_OK) == 0) &&
|
if ((access(cacertFile, R_OK) == 0) &&
|
||||||
virNetTLSContextLoadCACertListFromFile(cacertFile, cacerts, &ncacerts) < 0)
|
virNetTLSContextLoadCACertListFromFile(cacertFile, cacerts,
|
||||||
|
MAX_CERTS, &ncacerts) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (cert &&
|
if (cert &&
|
||||||
|
Loading…
Reference in New Issue
Block a user