[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 01/11] tlscontext: Make sure to get proper pointer to name



The 'dname' string was only filled in within the loop when available;
however, the TRACE macros used it unconditionally and caused Coverity
to compain about BAD_SIZEOF.  Using a dnameptr keeps Coverity at bay and
makes sure dname was properly filled before attempting the TRACE message.
---
 src/rpc/virnettlscontext.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/rpc/virnettlscontext.c b/src/rpc/virnettlscontext.c
index 0f0ddff..29d1508 100644
--- a/src/rpc/virnettlscontext.c
+++ b/src/rpc/virnettlscontext.c
@@ -1,7 +1,7 @@
 /*
  * virnettlscontext.c: TLS encryption/x509 handling
  *
- * Copyright (C) 2010-2012 Red Hat, Inc.
+ * Copyright (C) 2010-2013 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -950,6 +950,7 @@ static int virNetTLSContextValidCertificate(virNetTLSContextPtr ctxt,
     unsigned int nCerts, i;
     char dname[256];
     size_t dnamesize = sizeof(dname);
+    char *dnameptr = NULL;
 
     memset(dname, 0, dnamesize);
 
@@ -1025,6 +1026,7 @@ static int virNetTLSContextValidCertificate(virNetTLSContextPtr ctxt,
                                "[session]", gnutls_strerror(ret));
                 goto authfail;
             }
+            dnameptr = dname;
             VIR_DEBUG("Peer DN is %s", dname);
 
             if (virNetTLSContextCheckCertDN(cert, "[session]", sess->hostname, dname,
@@ -1062,14 +1064,14 @@ static int virNetTLSContextValidCertificate(virNetTLSContextPtr ctxt,
 
     PROBE(RPC_TLS_CONTEXT_SESSION_ALLOW,
           "ctxt=%p sess=%p dname=%s",
-          ctxt, sess, dname);
+          ctxt, sess, dnameptr ? dnameptr : "(unknown)");
 
     return 0;
 
 authdeny:
     PROBE(RPC_TLS_CONTEXT_SESSION_DENY,
           "ctxt=%p sess=%p dname=%s",
-          ctxt, sess, dname);
+          ctxt, sess, dnameptr ? dnameptr : "(unknown)");
 
     return -1;
 
-- 
1.7.11.7


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]