[gtk-vnc] Replace strncpy with memcpy in VNC password code



commit 4e5473b969ae95e431adf293c2bdbede3dc3b1b7
Author: Daniel P. Berrange <berrange redhat com>
Date:   Fri Dec 7 15:11:12 2012 +0000

    Replace strncpy with memcpy in VNC password code
    
    Using strncpy for the VNC key makes coverity worried about
    unterminated strings. Switch to use memcpy to keep it
    happier

 src/vncconnection.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/src/vncconnection.c b/src/vncconnection.c
index 7bc481a..df514b3 100644
--- a/src/vncconnection.c
+++ b/src/vncconnection.c
@@ -3311,6 +3311,7 @@ static gboolean vnc_connection_perform_auth_vnc(VncConnection *conn)
     VncConnectionPrivate *priv = conn->priv;
     guint8 challenge[16];
     guint8 key[8];
+    gsize keylen;
 
     VNC_DEBUG("Do Challenge");
     priv->want_cred_password = TRUE;
@@ -3324,8 +3325,11 @@ static gboolean vnc_connection_perform_auth_vnc(VncConnection *conn)
 
     vnc_connection_read(conn, challenge, 16);
 
-    memset(key, 0, 8);
-    strncpy((char*)key, (char*)priv->cred_password, 8);
+    memset(key, 0, sizeof(key));
+    keylen = strlen(priv->cred_password);
+    if (keylen > sizeof(key))
+        keylen = sizeof(key);
+    memcpy(key, priv->cred_password, keylen);
 
     deskey(key, EN0);
     des(challenge, challenge);



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