From nobody Thu May 16 02:04:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644506386; cv=none; d=zohomail.com; s=zohoarc; b=m8Zn08o2Cd2KowoZhCCFyMF4bcIwNktcpHe9ID+ZqoWRxfsWRG4f2j2hMCYt1NeRA4PkHUc5Y6baWNv4m4Zz2GR5ggyvFKWjuGYBUev0SALL5ifoAoeqhKXNceVcKyyBBHE/85Plvb0uwwxjbAaNxHlZ3wh5h5ma2B9qtqt5Fyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644506386; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0nl9fXV84SiRW0SzlZ3GXRi5UXnof+P2aafk4iylIt4=; b=gHw3F0EMrgd/zGwpWTkxCF62T0wvwTVhEwVMInkEiYE7YhItt4BlNmFZ5sA1N+FGzeUOnSugUlbU+r8cwHyvjbL6WvGG/4bQ82I6jawIvUYJMiID4+JV2ODfXXjrO/FeWUfTCMzjEtEdghxXz9VHeLeZdUHVhLZKEHMf7WOzebk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644506386980950.1483162366064; Thu, 10 Feb 2022 07:19:46 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-491-PqSZlyfePdansvWc06CXKg-1; Thu, 10 Feb 2022 10:19:44 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 269841926DA0; Thu, 10 Feb 2022 15:19:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E43A32B4DB; Thu, 10 Feb 2022 15:19:38 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 53FA51809CB8; Thu, 10 Feb 2022 15:19:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21AFJaJ0009325 for ; Thu, 10 Feb 2022 10:19:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 508F77DE24; Thu, 10 Feb 2022 15:19:36 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 260257DE2F for ; Thu, 10 Feb 2022 15:19:25 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 2804B2436A9; Thu, 10 Feb 2022 16:19:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644506386; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=0nl9fXV84SiRW0SzlZ3GXRi5UXnof+P2aafk4iylIt4=; b=Hkdxry/+OIYndPd4vnYFO8c/Z7D5saPabf9Og/G64PjdfJgXSPjY2rfmL0Z7i/7pvYHt5V LMsUJCE3gn5JyViFg5RdTZtje9R8hXB7AuxT5YgJj8JgTJqgYs0g8oML5jlqCCo7GDF4PZ XRG7QB4Jq5+bmFXI2c9PMT4Js4qTSEA= X-MC-Unique: PqSZlyfePdansvWc06CXKg-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH 1/2] qemu_migration_cookie: Rename ret in qemuDomainExtractTLSSubject Date: Thu, 10 Feb 2022 16:19:21 +0100 Message-Id: <337e5232824f0a507e5034c2dbb7e9c9b85d17f9.1644506344.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644506405533100001 Content-Type: text/plain; charset="utf-8" We use 'ret' for storing values to be returned from a function. Return values from called functions that are not supposed to be returned further are usually called 'rv' (or 'rc'). Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_migration_cookie.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_coo= kie.c index ba05a5a07f..76a01781d6 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -184,7 +184,7 @@ qemuDomainExtractTLSSubject(const char *certdir) g_autofree char *pemdata =3D NULL; gnutls_datum_t pemdatum; gnutls_x509_crt_t cert; - int ret; + int rc; size_t subjectlen; =20 certfile =3D g_strdup_printf("%s/server-cert.pem", certdir); @@ -195,22 +195,22 @@ qemuDomainExtractTLSSubject(const char *certdir) return NULL; } =20 - ret =3D gnutls_x509_crt_init(&cert); - if (ret < 0) { + rc =3D gnutls_x509_crt_init(&cert); + if (rc < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot initialize cert object: %s"), - gnutls_strerror(ret)); + gnutls_strerror(rc)); return NULL; } =20 pemdatum.data =3D (unsigned char *)pemdata; pemdatum.size =3D strlen(pemdata); =20 - ret =3D gnutls_x509_crt_import(cert, &pemdatum, GNUTLS_X509_FMT_PEM); - if (ret < 0) { + rc =3D gnutls_x509_crt_import(cert, &pemdatum, GNUTLS_X509_FMT_PEM); + if (rc < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot load cert data from %s: %s"), - certfile, gnutls_strerror(ret)); + certfile, gnutls_strerror(rc)); return NULL; } =20 --=20 2.35.1 From nobody Thu May 16 02:04:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644506416; cv=none; d=zohomail.com; s=zohoarc; b=dtbyC0JapIZ2wAmK6XfZjAbjTfAO2tV4pAUr5EvCxprH7b7fV8g2RXxeAeU5W84QErApkSihnV/hUagR2+CKX4nO3CD9X3svLh21ZiYC8goHp981OWcHbvQwnFJYC3BuRdYJRoY9WP15tuehll4OtbXaVVclORZp2yHfOULBjQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644506416; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5CF2zTIbSWCc1biUtRPno4dGc+X/pY0tqMstcmhb4PM=; b=Nj4lYQ8nCijDPEiFZhZCY08hHJwPIy3voRwuqq5QtKoCQMmP2F4xCUrxQbBZcQZBgq56MKQACvsIk1qNrnpzI8NRmwLsO863hhhdTYUxqpEHXJlqMZLi14Upcajkhk0Qfohx/NCNac7J4cVGvbTRZmLX1ZmfVW2QntFnkIDig4w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644506416853199.39085835182505; Thu, 10 Feb 2022 07:20:16 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-593-hAcvy6APP-WKvozBJyhQZA-1; Thu, 10 Feb 2022 10:19:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3ECE1091DA2; Thu, 10 Feb 2022 15:19:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B1D027DE29; Thu, 10 Feb 2022 15:19:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 844394CA9B; Thu, 10 Feb 2022 15:19:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21AFJaUn009324 for ; Thu, 10 Feb 2022 10:19:36 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5095C7DE29; Thu, 10 Feb 2022 15:19:36 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.187]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 25D077DE2E for ; Thu, 10 Feb 2022 15:19:25 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id 297C12436AA; Thu, 10 Feb 2022 16:19:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644506415; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5CF2zTIbSWCc1biUtRPno4dGc+X/pY0tqMstcmhb4PM=; b=TRauzNuSzvh0BMAPlMg5u+6PYgEXyiPsq9yG5+bCDmznwK6HpzTvupWQro9Qa+CkokpQbS JPcjBW74+40dQkTE1LV25iI5jcMXtRvmusbFbhVuu+APp0fr6Jq3HLOwrXa6aeiaigHS1M d//Kouyq84/uG0nvov1Wtc7uEdy/2H8= X-MC-Unique: hAcvy6APP-WKvozBJyhQZA-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH 2/2] qemu_migration_cookie: Properly fetch cert DN Date: Thu, 10 Feb 2022 16:19:22 +0100 Message-Id: <3d351a03e66e968483674f9770fa9a97a65e625e.1644506344.git.jdenemar@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644506420677100003 Content-Type: text/plain; charset="utf-8" If 1024 was not enough to fit the DN, gnutls_x509_crt_get_dn would store the required size in subjectlen. And since we're not checking the return value of this function, we would happily overwrite some random memory. Signed-off-by: Jiri Denemark Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_migration_cookie.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_coo= kie.c index 76a01781d6..046d588d8a 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -180,12 +180,12 @@ static char * qemuDomainExtractTLSSubject(const char *certdir) { g_autofree char *certfile =3D NULL; - char *subject =3D NULL; + g_autofree char *subject =3D NULL; g_autofree char *pemdata =3D NULL; gnutls_datum_t pemdatum; gnutls_x509_crt_t cert; int rc; - size_t subjectlen; + size_t subjectlen =3D 0; =20 certfile =3D g_strdup_printf("%s/server-cert.pem", certdir); =20 @@ -214,13 +214,20 @@ qemuDomainExtractTLSSubject(const char *certdir) return NULL; } =20 - subjectlen =3D 1024; - subject =3D g_new0(char, subjectlen + 1); - - gnutls_x509_crt_get_dn(cert, subject, &subjectlen); + rc =3D gnutls_x509_crt_get_dn(cert, NULL, &subjectlen); + if (rc =3D=3D GNUTLS_E_SHORT_MEMORY_BUFFER) { + subject =3D g_new0(char, subjectlen + 1); + rc =3D gnutls_x509_crt_get_dn(cert, subject, &subjectlen); + } + if (rc !=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot get cert distinguished name: %s"), + gnutls_strerror(rc)); + return NULL; + } subject[subjectlen] =3D '\0'; =20 - return subject; + return g_steal_pointer(&subject); } =20 =20 --=20 2.35.1