From nobody Thu May 16 00:03:16 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=1644582610; cv=none; d=zohomail.com; s=zohoarc; b=X69k/e1nkc3IcmAYLwwY8MtZQN9p2PTgf1pkPeIBckWZb0qvjKa/WD/BvRvr5tQ+WUBKglLvQxeZj8/3KqdU78x1EpQH4OaOmCmEVROje6I3itrZEkGfSh7xmHOMvufJlTJH4YKbz57SkH6yndvj4tNKSIIHrXLFYxquQpvUaB4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644582610; 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=PvhCXTUx2g9CmjAtbmRfwoeynTU/GqfI9i1WvbDF/+I=; b=jj/0tGEnV6jP+3o0f/Gu7FcqDuAOCe8FV8hyoNDdNro9qBJSHfGoxKPZlLuk5esBUpzH7brBZJk0AlFDEQ5DNERJIoBQzzWiz5FxjVbhGzAYTRil1IzNwwe+l8OyA1cc4Yx4dCfvd6PoUoRNAkZkfZS9dfcTmX44oGbmwuDxWxE= 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 164458261043268.81775500667948; Fri, 11 Feb 2022 04:30:10 -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-635-7F3ppumiMRCrQynorcrtNA-1; Fri, 11 Feb 2022 07:30:05 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ADE8D18B9F60; Fri, 11 Feb 2022 12:30:00 +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 3D3ADBF676; Fri, 11 Feb 2022 12:29:57 +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 AFFC74BB7C; Fri, 11 Feb 2022 12:29:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BCTnPv008725 for ; Fri, 11 Feb 2022 07:29:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id DE66F2B3A0; Fri, 11 Feb 2022 12:29:49 +0000 (UTC) Received: from rein.int.mamuti.net (unknown [10.40.192.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B29652B4B1 for ; Fri, 11 Feb 2022 12:29:38 +0000 (UTC) Received: by rein.int.mamuti.net (Postfix, from userid 500) id B64571807F4; Fri, 11 Feb 2022 13:29:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644582609; 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=PvhCXTUx2g9CmjAtbmRfwoeynTU/GqfI9i1WvbDF/+I=; b=X9EnXhTTHYkzYAlxnVWWtxaL8+RIrX+fX0vq2R5Pnp2q5ztU0xEEGWxqUYlsWOoe/BLY7H 0D56f50Pge7WAl9P7xtCji3mk9puZxrIEJgZERu/ru5IMThKdXcVi3ja0HXZn2+gRRMWIy A+zfYMlB1CHx7B0xdLBv4MGmMlXuPzY= X-MC-Unique: 7F3ppumiMRCrQynorcrtNA-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/2] qemu_migration_cookie: Rename ret in qemuDomainExtractTLSSubject Date: Fri, 11 Feb 2022 13:29:33 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.13 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644582611129100001 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 --- Notes: Version 2: - no change 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.0 From nobody Thu May 16 00:03:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1644582596; cv=none; d=zohomail.com; s=zohoarc; b=nhHYKKnXLgo2KeCgH8MYCt+5Xk7VA72TR2LjAhZppDXzcQlQEXt+sdAEm1AufImYOtrLQ/RviPo2DZP459R09gvDKSlcWrm4JZWSMyUB8aqTzp4XW+HgJYu+7ULRzvqzIgjRiGCoKfHRByamjg3o4WKQPGMkKXCMBOjOHTk9Efs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644582596; 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=hv/Kp+QVEoruHYCouwITI6Kz2oMdXgh9oAGM3quChJY=; b=TzZ3QV/HDYHQruKPwJtiL6ijpJ30zKYtJnX6o6fmsIO/JgDJmotOt/LqXDf+TPhJPf28WzNwp5c81jeRyRmrUkvHd8w4iQr9iBH+lgM80kRZPEIFUPx+2OfhI0/xhct7BVN+6ldEXxbuHwDwY61qJ+Os0xLs1yEYxpLvitQFzes= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1644582596322921.0377960926816; Fri, 11 Feb 2022 04:29:56 -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-538-syfksfplO9uuG-4K4De4Ig-1; Fri, 11 Feb 2022 07:29:51 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90582101F008; Fri, 11 Feb 2022 12:29:45 +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 CAFB670F52; Fri, 11 Feb 2022 12:29:43 +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 ABC301809CB8; Fri, 11 Feb 2022 12:29:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BCTds6008710 for ; Fri, 11 Feb 2022 07:29:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id EFA2084A3C; Fri, 11 Feb 2022 12:29:38 +0000 (UTC) Received: from rein.int.mamuti.net (unknown [10.40.192.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7862785883 for ; Fri, 11 Feb 2022 12:29:38 +0000 (UTC) Received: by rein.int.mamuti.net (Postfix, from userid 500) id B8C8C18ADF5; Fri, 11 Feb 2022 13:29:36 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644582595; 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=hv/Kp+QVEoruHYCouwITI6Kz2oMdXgh9oAGM3quChJY=; b=GlEjmQZAJrqcd3l95jZ8jkPmBd3YYLfnfzIUJwcriuqFGu3C8GLw8NyvEtlbifJGjejX8c 9w5rSlKryoBk7SqRDzaVz2gv9z9AyUwTbXO9txxo+h+/jpy5trg3jP21d91fG3UcLQ5luq qQ0rK2YSNG9iHguCsmWMxckpnUh0TyI= X-MC-Unique: syfksfplO9uuG-4K4De4Ig-1 From: Jiri Denemark To: libvir-list@redhat.com Subject: [libvirt PATCH v2 2/2] qemu_migration_cookie: Properly fetch cert DN Date: Fri, 11 Feb 2022 13:29:34 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.15 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: 1644582598019100001 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: Michal Privoznik --- Notes: Version 2: - do not pass NULL to the first gnutls_x509_crt_get_dn call src/qemu/qemu_migration_cookie.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_coo= kie.c index 76a01781d6..5d14e271c1 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 256; =20 certfile =3D g_strdup_printf("%s/server-cert.pem", certdir); =20 @@ -214,13 +214,21 @@ 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, subject, &subjectlen); + if (rc =3D=3D GNUTLS_E_SHORT_MEMORY_BUFFER) { + subject =3D g_realloc(subject, 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.0