Blob Blame History Raw
From 1f2a7a079a42ac9bccc12749c5eac4fcdbd48b2e Mon Sep 17 00:00:00 2001
From: Frediano Ziglio <freddy77@gmail.com>
Date: Wed, 16 Sep 2020 17:12:14 +0100
Subject: [PATCH 30/31] channel-main: Make more clear that host_data and
 cert_subject_data are C strings

After commit ab42be2b00d12d0bc98c6ddea08a7f969e83b2ac ("channel-main:
Copy SpiceMigrationDstInfo into spice_migrate") host_data and
cert_subject_data fields in spice_migrate structure are proper
terminated C strings so:
- check pointer instead of related field;
- you don't need to terminate again.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <uril@redhat.com>
---
 src/channel-main.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/channel-main.c b/src/channel-main.c
index 5f81975..2881d59 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -2412,18 +2412,14 @@ static gboolean migrate_connect(spice_migrate *mig)
     sport = info->sport;
     host = (char*)info->host_data;
 
-    if (info->cert_subject_size == 0 ||
+    if (info->cert_subject_data == NULL ||
         strlen((const char*)info->cert_subject_data) == 0) {
         /* only verify hostname if no cert subject */
         g_object_set(mig->session, "verify", SPICE_SESSION_VERIFY_HOSTNAME, NULL);
     } else {
-        gchar *subject = g_alloca(info->cert_subject_size + 1);
-        strncpy(subject, (const char*)info->cert_subject_data, info->cert_subject_size);
-        subject[info->cert_subject_size] = '\0';
-
         // session data are already copied
         g_object_set(mig->session,
-                     "cert-subject", subject,
+                     "cert-subject", info->cert_subject_data,
                      "verify", SPICE_SESSION_VERIFY_SUBJECT,
                      NULL);
     }
-- 
2.28.0