From nobody Fri May 3 23:07:19 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=canonical.com 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 1634906767874820.6253664680911; Fri, 22 Oct 2021 05:46:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-242-oZaL1uViMRqQxiTqXDy-dg-1; Fri, 22 Oct 2021 08:46:03 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EDBED801FCE; Fri, 22 Oct 2021 12:45:57 +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 265A218351; Fri, 22 Oct 2021 12:45: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 32C4F4A704; Fri, 22 Oct 2021 12:45:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19MCjpDS011512 for ; Fri, 22 Oct 2021 08:45:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8D6FB40CFD11; Fri, 22 Oct 2021 12:45:51 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 882AB40CFD07 for ; Fri, 22 Oct 2021 12:45:51 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6BD7B80015A for ; Fri, 22 Oct 2021 12:45:51 +0000 (UTC) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-291-k1J62kaiM6SQw-fsRNZ-xw-1; Fri, 22 Oct 2021 08:45:49 -0400 Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id EE2AA3FFEE for ; Fri, 22 Oct 2021 12:45:47 +0000 (UTC) Received: by mail-lf1-f72.google.com with SMTP id x17-20020a0565123f9100b003ff593b7c65so1679597lfa.12 for ; Fri, 22 Oct 2021 05:45:47 -0700 (PDT) Received: from ws.lan.d-node.is ([95.165.29.203]) by smtp.gmail.com with ESMTPSA id e8sm722655lft.308.2021.10.22.05.45.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 05:45:46 -0700 (PDT) X-MC-Unique: oZaL1uViMRqQxiTqXDy-dg-1 X-MC-Unique: k1J62kaiM6SQw-fsRNZ-xw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eoqe/PQkgnUX0tHOLIL0W4xXMKDXq+gmuwCHp8j/xbQ=; b=3mCyOn904MC1pRp3myWcD9qnkoNOgRedGbSSW8uuFfvwYvEibyRgQRQtxPl2L+4UOY aasHOq5DpDqKb64kzNapeSKhLEouJ8c/KkG+Bwt1EHogy3D4DoQ3I+jCLJGJe3K32qT4 N1X3V8iww07iuUAmfu/0t9fY2XnUVcfZDbrfQmD/m6dFbw+Y6y4AiXlcsfBJ84ve63MC rKftlMMVq9hK4O3y/D5IuqU3YWZL/Hzz3wOJTcq1C+I/bS9RrrEOnlOeNkINx2apHPGB bBnezFMcvsMv5AC5b+2bnHCvePQUq5ds6DXnhC9psDXY8fxS9LT4zWn90sV/BIcz/SfZ JbLA== X-Gm-Message-State: AOAM530d8/A6RBVHEWzMzCutcpMnJBTo2xkTXdE3oeV9bVPHjFWoHI0W PATkIl62WjGnDMa2Dctrj720RNrqLGoFNl5zSeicqz/TuuwsLPbn55Y4RFHqx0KIEi54srh0baV 68rgt4BREiq1sIrt1R13lhnHaP79oinnWVw== X-Received: by 2002:a2e:b162:: with SMTP id a2mr12621294ljm.440.1634906747361; Fri, 22 Oct 2021 05:45:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJza2mO+YlvZ+ZjGag/XGi5ODsY2/15uk9CJFYghXlOggX7TDhpP9/ZnFlWgaDB9RTfo8v1QMQ== X-Received: by 2002:a2e:b162:: with SMTP id a2mr12621268ljm.440.1634906747108; Fri, 22 Oct 2021 05:45:47 -0700 (PDT) From: Dmitrii Shcherbakov To: dmitrii.shcherbakov@canonical.com, libvir-list@redhat.com Subject: [libvirt PATCH 1/4] PCI VPD: handle additional edge cases Date: Fri, 22 Oct 2021 15:45:42 +0300 Message-Id: <20211022124545.412352-2-dmitrii.shcherbakov@canonical.com> In-Reply-To: <20211022124545.412352-1-dmitrii.shcherbakov@canonical.com> References: <20211022124545.412352-1-dmitrii.shcherbakov@canonical.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 19MCjpDS011512 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.14 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-ZM-MESSAGEID: 1634906769937100003 Content-Type: text/plain; charset="utf-8" * RV and RW fields must be at the last position in their respective section (per the conditions in the spec). Therefore, the parser now stops iterating over fields as soon as it encounters one of those fields and checks whether the end of the resource has been reached; * Individual fields must have a valid length - the parser needs to check for invalid length values that violate boundary conditions of the resource. * A zero-length field may be the last one in the resource, however, the boundary check is currently too strict to allow that. Signed-off-by: Dmitrii Shcherbakov --- src/util/virpcivpd.c | 28 +++++++++++---- tests/virpcivpdtest.c | 84 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 6 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index 8856bca459..cd49031fa4 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -466,8 +466,12 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, ui= nt16_t resPos, uint16_t re =20 bool hasChecksum =3D false; bool hasRW =3D false; + bool endReached =3D false; =20 - while (fieldPos + 3 < resPos + resDataLen) { + /* Note the equal sign - fields may have a zero length in which case t= hey will + * just occupy 3 header bytes. In the in case of the RW field this may= mean that + * no more space is left in the section. */ + while (fieldPos + 3 <=3D resPos + resDataLen) { /* Keyword resources consist of keywords (2 ASCII bytes per the sp= ec) and 1-byte length. */ if (virPCIVPDReadVPDBytes(vpdFileFd, buf, 3, fieldPos, csum) !=3D = 3) { /* Invalid field encountered which means the resource itself i= s invalid too. Report @@ -518,6 +522,13 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, ui= nt16_t resPos, uint16_t re return false; } =20 + if (resPos + resDataLen < fieldPos + fieldDataLen) { + /* In this case the field cannot simply be skipped since the p= osition of the + * next field is determined based on the length of a previous = field. */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("A field data length violates the resource le= ngth boundary.")); + return false; + } if (virPCIVPDReadVPDBytes(vpdFileFd, buf, bytesToRead, fieldPos, c= sum) !=3D bytesToRead) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not parse a resource field data - VPD = has invalid format")); @@ -546,12 +557,13 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, u= int16_t resPos, uint16_t re hasChecksum =3D true; g_free(g_steal_pointer(&fieldKeyword)); g_free(g_steal_pointer(&fieldValue)); - continue; + break; } else if (fieldFormat =3D=3D VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FOR= MAT_RDWR) { /* Skip the read-write space since it is used for indication o= nly. */ hasRW =3D true; g_free(g_steal_pointer(&fieldKeyword)); g_free(g_steal_pointer(&fieldValue)); + break; } else if (fieldFormat =3D=3D VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FOR= MAT_LAST) { /* Skip unknown fields */ g_free(g_steal_pointer(&fieldKeyword)); @@ -579,13 +591,17 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, u= int16_t resPos, uint16_t re g_free(g_steal_pointer(&fieldKeyword)); g_free(g_steal_pointer(&fieldValue)); } - if (readOnly && !hasChecksum) { + + /* May have exited the loop prematurely in case RV or RW were encounte= red and + * they were not the last fields in the section. */ + endReached =3D (fieldPos >=3D resPos + resDataLen); + if (readOnly && !(hasChecksum && endReached)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("VPD-R does not contain the mandatory RV field")); + _("VPD-R does not contain the mandatory RV field as the la= st field")); return false; - } else if (!readOnly && !hasRW) { + } else if (!readOnly && !(hasRW && endReached)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("VPD-W does not contain the mandatory RW field")); + _("VPD-W does not contain the mandatory RW field as= the last field")); return false; } =20 diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index 2cc9069132..65607c1247 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -597,6 +597,58 @@ testVirPCIVPDParseFullVPD(const void *opaque G_GNUC_UN= USED) return ret; } =20 +static int +testVirPCIVPDParseZeroLengthRW(const void *opaque G_GNUC_UNUSED) +{ + int fd =3D -1; + size_t dataLen =3D 0; + + g_autoptr(virPCIVPDResource) res =3D NULL; + virPCIVPDResourceCustom *custom =3D NULL; + + /* The RW field has a zero length which means there is no more RW spa= ce left. */ + const uint8_t fullVPDExample[] =3D { + VPD_STRING_RESOURCE_EXAMPLE_HEADER, VPD_STRING_RESOURCE_EXAMPLE_DA= TA, + VPD_R_FIELDS_EXAMPLE_HEADER, VPD_R_FIELDS_EXAMPLE_DATA, + PCI_VPD_LARGE_RESOURCE_FLAG | PCI_VPD_READ_WRITE_LARGE_RESOURCE_FL= AG, 0x08, 0x00, + 'V', 'Z', 0x02, '4', '2', + 'R', 'W', 0x00, + PCI_VPD_RESOURCE_END_VAL + }; + + dataLen =3D sizeof(fullVPDExample) / sizeof(uint8_t); + fd =3D virCreateAnonymousFile(fullVPDExample, dataLen); + res =3D virPCIVPDParse(fd); + VIR_FORCE_CLOSE(fd); + + if (!res) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "The resource pointer is NULL after parsing which i= s unexpected"); + return -1; + } + + if (!res->ro) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Read-only keywords are missing from the VPD resource."); + return -1; + } else if (!res->rw) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Read-write keywords are missing from the VPD resource."); + return -1; + } + + if (testVirPCIVPDValidateExampleReadOnlyFields(res)) + return -1; + + custom =3D g_ptr_array_index(res->rw->vendor_specific, 0); + if (custom->idx !=3D 'Z' || STRNEQ_NULLABLE(custom->value, "42")) + return -1; + + custom =3D NULL; + return 0; +} + + static int testVirPCIVPDParseFullVPDSkipInvalidKeywords(const void *opaque G_GNUC_UNU= SED) { @@ -717,6 +769,32 @@ testVirPCIVPDParseFullVPDInvalid(const void *opaque G_= GNUC_UNUSED) 'R', 'V', 0x02, 0x8A, 0x00, \ PCI_VPD_RESOURCE_END_VAL =20 +/* The SN field has a length field that goes past the resource boundaries.= */ +# define VPD_INVALID_SN_FIELD_LENGTH \ + VPD_STRING_RESOURCE_EXAMPLE_HEADER, \ + 't', 'e', 's', 't', 'n', 'a', 'm', 'e', \ + PCI_VPD_LARGE_RESOURCE_FLAG | PCI_VPD_READ_ONLY_LARGE_RESOURCE_FLAG, 0= x0A, 0x00, \ + 'S', 'N', 0x42, 0x04, 0x02, \ + 'R', 'V', 0x02, 0xE8, 0x00, \ + PCI_VPD_RESOURCE_END_VAL + +/* The RV field is not the last one in VPD-R while the checksum is valid. = */ +# define VPD_INVALID_RV_NOT_LAST \ + VPD_STRING_RESOURCE_EXAMPLE_HEADER, \ + 't', 'e', 's', 't', 'n', 'a', 'm', 'e', \ + PCI_VPD_LARGE_RESOURCE_FLAG | PCI_VPD_READ_ONLY_LARGE_RESOURCE_FLAG, 0= x0A, 0x00, \ + 'R', 'V', 0x02, 0xD1, 0x00, \ + 'S', 'N', 0x02, 0x04, 0x02, \ + PCI_VPD_RESOURCE_END_VAL + +# define VPD_INVALID_RW_NOT_LAST \ + VPD_STRING_RESOURCE_EXAMPLE_HEADER, VPD_STRING_RESOURCE_EXAMPLE_DATA, \ + VPD_R_FIELDS_EXAMPLE_HEADER, VPD_R_FIELDS_EXAMPLE_DATA, \ + PCI_VPD_LARGE_RESOURCE_FLAG | PCI_VPD_READ_WRITE_LARGE_RESOURCE_FLAG, = 0x08, 0x00, \ + 'R', 'W', 0x00, \ + 'V', 'Z', 0x02, '4', '2', \ + PCI_VPD_RESOURCE_END_VAL + # define TEST_INVALID_VPD(invalidVPD) \ do { \ g_autoptr(virPCIVPDResource) res =3D NULL; \ @@ -741,6 +819,9 @@ testVirPCIVPDParseFullVPDInvalid(const void *opaque G_G= NUC_UNUSED) TEST_INVALID_VPD(VPD_R_UNEXPECTED_RW_IN_VPD_R_KEY); TEST_INVALID_VPD(VPD_R_INVALID_FIELD_VALUE); TEST_INVALID_VPD(VPD_INVALID_STRING_RESOURCE_VALUE); + TEST_INVALID_VPD(VPD_INVALID_SN_FIELD_LENGTH); + TEST_INVALID_VPD(VPD_INVALID_RV_NOT_LAST); + TEST_INVALID_VPD(VPD_INVALID_RW_NOT_LAST); =20 return 0; } @@ -767,6 +848,9 @@ mymain(void) ret =3D -1; if (virTestRun("Parsing VPD string resources ", testVirPCIVPDParseVPDS= tringResource, NULL) < 0) ret =3D -1; + if (virTestRun("Parsing a VPD resource with a zero-length RW ", + testVirPCIVPDParseZeroLengthRW, NULL) < 0) + ret =3D -1; if (virTestRun("Parsing a VPD resource with an invalid keyword ", testVirPCIVPDParseFullVPDSkipInvalidKeywords, NULL) < 0) ret =3D -1; --=20 2.32.0 From nobody Fri May 3 23:07:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=canonical.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1634906823346877.6791317484915; Fri, 22 Oct 2021 05:47:03 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-565-7Sa25xATOgSaCzA2fjYeGA-1; Fri, 22 Oct 2021 08:46:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D48B1006AA4; Fri, 22 Oct 2021 12:46:17 +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 2F24D5DEFB; Fri, 22 Oct 2021 12:46:17 +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 EE23F1800B9E; Fri, 22 Oct 2021 12:46:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19MCjs2I011534 for ; Fri, 22 Oct 2021 08:45:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4C14B1007272; Fri, 22 Oct 2021 12:45:54 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4836F100726A for ; Fri, 22 Oct 2021 12:45:51 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B9F38007B1 for ; Fri, 22 Oct 2021 12:45:51 +0000 (UTC) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-445-2YMG9z0bPUGCco63edn4sw-1; Fri, 22 Oct 2021 08:45:49 -0400 Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 298AA3FFFC for ; Fri, 22 Oct 2021 12:45:48 +0000 (UTC) Received: by mail-lf1-f72.google.com with SMTP id p10-20020a056512234a00b003fe188e9960so1660480lfu.19 for ; Fri, 22 Oct 2021 05:45:48 -0700 (PDT) Received: from ws.lan.d-node.is ([95.165.29.203]) by smtp.gmail.com with ESMTPSA id e8sm722655lft.308.2021.10.22.05.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 05:45:47 -0700 (PDT) X-MC-Unique: 7Sa25xATOgSaCzA2fjYeGA-1 X-MC-Unique: 2YMG9z0bPUGCco63edn4sw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0cHyDeDbuEjki0WferXinFOTS0OtNPVDrkPz2dGV8Jg=; b=2LnR6qcmis9jL6CveRr4SeW+ekyhz84RqdVDy2aKGU/rTTFejBAXB1gmFFOPKfn3dk +9qWrZBSWa1PfvJOkz5N5NKC2uQx1gjBYwG7MT4K0BEybXGPxa9UsV2GNfBo4kLqsDtV QMIPxs4pFHJY5qmxGGyem5jvpMP4Zzsd9OFeN7IcsFbyikaMYVtTPKN0DV5sgO3zPtNG n8Zt+6qJZgqPWy7Yqf8a3iYcB5cK2yJl+gpGH03nx6zQwP3Gjiti4AxN/J2tiQ+qwt8a W8SRjlsj2b1tO36xnoq9CiJSrpFbRKgf8Ed4mZuoIXehGbLiyQfXSNrM3ZOsHnLKIofO mN6g== X-Gm-Message-State: AOAM531lizbKocN9G5f/rwH397E1Ww2PBWleioCE6hh5kAju+/w5/Wz3 DD/z8kRk/CrPUTI3ExthQ8+vUdYn02Ije05j9YYR9AcNWqqu0S/Lam6Dyc+qvxmcFS1A4ZZtujA 3yiNgBFoZiU+pylA7stU+61h099NT8/vXlA== X-Received: by 2002:ac2:5f0d:: with SMTP id 13mr11131535lfq.334.1634906747660; Fri, 22 Oct 2021 05:45:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNpMQ3cApiMHO0Z1NwQkXk7xt9CWHFFH8XSZ98PPlDBKwhs2fzseT1WZ43Keq6pTOF/hBzmA== X-Received: by 2002:ac2:5f0d:: with SMTP id 13mr11131519lfq.334.1634906747504; Fri, 22 Oct 2021 05:45:47 -0700 (PDT) From: Dmitrii Shcherbakov To: dmitrii.shcherbakov@canonical.com, libvir-list@redhat.com Subject: [libvirt PATCH 2/4] PCI VPD: Add a test case for the absence of RW Date: Fri, 22 Oct 2021 15:45:43 +0300 Message-Id: <20211022124545.412352-3-dmitrii.shcherbakov@canonical.com> In-Reply-To: <20211022124545.412352-1-dmitrii.shcherbakov@canonical.com> References: <20211022124545.412352-1-dmitrii.shcherbakov@canonical.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 19MCjs2I011534 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.14 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-ZM-MESSAGEID: 1634906824643100001 Content-Type: text/plain; charset="utf-8" The code already handles a missing RW, however, there was no test case for that. It would be good to have it since a VPD like this was encountered on a real-world device. Signed-off-by: Dmitrii Shcherbakov --- tests/virpcivpdtest.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index 65607c1247..00e34cc94a 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -795,6 +795,22 @@ testVirPCIVPDParseFullVPDInvalid(const void *opaque G_= GNUC_UNUSED) 'V', 'Z', 0x02, '4', '2', \ PCI_VPD_RESOURCE_END_VAL =20 +# define VPD_INVALID_NO_RW \ + 0x82, 0x23, 0x00, 0x48, 0x50, 0x20, 0x45, 0x74, 0x68, 0x65, 0x72, 0x6e= , 0x65, 0x74, \ + 0x20, 0x31, 0x47, 0x62, 0x20, 0x32, 0x2d, 0x70, 0x6f, 0x72, 0x74, 0x20= , 0x33, 0x36, \ + 0x31, 0x69, 0x20, 0x41, 0x64, 0x61, 0x70, 0x74, 0x65, 0x72, 0x90, 0x42= , 0x00, 0x50, \ + 0x4e, 0x03, 0x4e, 0x2f, 0x41, 0x45, 0x43, 0x03, 0x4e, 0x2f, 0x41, 0x53= , 0x4e, 0x03, \ + 0x4e, 0x2f, 0x41, 0x56, 0x30, 0x29, 0x34, 0x57, 0x2f, 0x31, 0x57, 0x20= , 0x50, 0x43, \ + 0x49, 0x65, 0x47, 0x32, 0x78, 0x34, 0x20, 0x32, 0x70, 0x20, 0x31, 0x47= , 0x62, 0x45, \ + 0x20, 0x52, 0x4a, 0x34, 0x35, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x6c, 0x20= , 0x69, 0x33, \ + 0x35, 0x30, 0x20, 0x20, 0x20, 0x52, 0x56, 0x01, 0x63, 0x91, 0x47, 0x00= , 0x56, 0x31, \ + 0x06, 0x35, 0x2e, 0x37, 0x2e, 0x30, 0x36, 0x56, 0x33, 0x06, 0x32, 0x2e= , 0x38, 0x2e, \ + 0x32, 0x30, 0x56, 0x36, 0x06, 0x31, 0x2e, 0x35, 0x2e, 0x33, 0x35, 0x59= , 0x41, 0x03, \ + 0x4e, 0x2f, 0x41, 0x59, 0x42, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff= , 0xff, 0xff, \ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x59, 0x43, 0x10, 0xFF= , 0xFF, 0xFF, \ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff= , 0xff, 0x78 + + # define TEST_INVALID_VPD(invalidVPD) \ do { \ g_autoptr(virPCIVPDResource) res =3D NULL; \ @@ -822,6 +838,7 @@ testVirPCIVPDParseFullVPDInvalid(const void *opaque G_G= NUC_UNUSED) TEST_INVALID_VPD(VPD_INVALID_SN_FIELD_LENGTH); TEST_INVALID_VPD(VPD_INVALID_RV_NOT_LAST); TEST_INVALID_VPD(VPD_INVALID_RW_NOT_LAST); + TEST_INVALID_VPD(VPD_INVALID_NO_RW); =20 return 0; } --=20 2.32.0 From nobody Fri May 3 23:07:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=canonical.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1634906791050996.7279155142867; Fri, 22 Oct 2021 05:46:31 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-489-ORPkjsvaOLCQEcfZsNsAaA-1; Fri, 22 Oct 2021 08:46:26 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0D539180830C; Fri, 22 Oct 2021 12:46:21 +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 E4BF8101E589; Fri, 22 Oct 2021 12:46:20 +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 AF4A84EA2F; Fri, 22 Oct 2021 12:46:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19MCjtNb011540 for ; Fri, 22 Oct 2021 08:45:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id E9FD62166B25; Fri, 22 Oct 2021 12:45:54 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E45C02166B2D for ; Fri, 22 Oct 2021 12:45:53 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 769A0811E78 for ; Fri, 22 Oct 2021 12:45:53 +0000 (UTC) Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-467-sTNm3YuZORmbMjXVv0zRow-1; Fri, 22 Oct 2021 08:45:50 -0400 Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id BD5844000B for ; Fri, 22 Oct 2021 12:45:48 +0000 (UTC) Received: by mail-lf1-f69.google.com with SMTP id br42-20020a056512402a00b003fd94a74905so1691801lfb.7 for ; Fri, 22 Oct 2021 05:45:48 -0700 (PDT) Received: from ws.lan.d-node.is ([95.165.29.203]) by smtp.gmail.com with ESMTPSA id e8sm722655lft.308.2021.10.22.05.45.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 05:45:47 -0700 (PDT) X-MC-Unique: ORPkjsvaOLCQEcfZsNsAaA-1 X-MC-Unique: sTNm3YuZORmbMjXVv0zRow-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SGfQkBivon1htZdfTTv0HIJP2GETQ5HsNDhoxwD6n0w=; b=U/hVgrIwlS7n1XTQbmOB3Dx4lIiw1I+EK6bUDxKgQOHEqHVSPCXafCi8d5m181PdJs OUcNEeAFb+8s/Si6f123j5TZgL9VJWETtM6nI3rvaWhdDb2uSnyywE3aacK8qNegAyWN pVU4KHxkeoBHl8vJZY3jbUkozyw/qlj5kyb3yZmoQWDGSAkWdLO7cfw1jm8IMtIzy3Fy qqAIJT6yFB0TpbSzJlfkEsrwgrC7nFyqbyludXICDoLafzxG4ltrprtXEbYufTJ4/rIo XQUBRCC3WYiO9sS/K4O/6KR0egyfT8nVqfIEpSNf5h3YlXQjp/w96zGlt2IYCzobn70z zOVA== X-Gm-Message-State: AOAM533boF+qPeycjIqZpxE4mfNJXuGDEIiVWhKnXcbYFl0B43o1gDZd 6AJyGGz4gUmcni0gbLBhDBaPvT57iPJ1Cs7hLftd4cgM0hzgA3kgGC/hBxsTwaZzUVGaMV+2TY/ FOgJRf7/MGVOQ0Ksm3Qx908QChl8Ue0Sm5A== X-Received: by 2002:a2e:bd0b:: with SMTP id n11mr12673560ljq.71.1634906748202; Fri, 22 Oct 2021 05:45:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAp5qxJlmYj3Pb+kxawR3N+NG5H0K9xTVOFelIMePtZZDluSJC1F8ffyQFhOQxFJUkFHFXUA== X-Received: by 2002:a2e:bd0b:: with SMTP id n11mr12673533ljq.71.1634906747936; Fri, 22 Oct 2021 05:45:47 -0700 (PDT) From: Dmitrii Shcherbakov To: dmitrii.shcherbakov@canonical.com, libvir-list@redhat.com Subject: [libvirt PATCH 3/4] PCI VPD: Skip fields with invalid values Date: Fri, 22 Oct 2021 15:45:44 +0300 Message-Id: <20211022124545.412352-4-dmitrii.shcherbakov@canonical.com> In-Reply-To: <20211022124545.412352-1-dmitrii.shcherbakov@canonical.com> References: <20211022124545.412352-1-dmitrii.shcherbakov@canonical.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 19MCjtNb011540 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.22 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-ZM-MESSAGEID: 1634906792851100001 Content-Type: text/plain; charset="utf-8" While invalid values need to be ignored when presenting VPD data to the user, it would be good to attempt to parse a valid portion of the VPD instead of marking it invalid as a whole. The particular example encountered on real hardware was twofold: * "N/A" strings present in read-only fields. This would not be a useful valid value for a field, not to mention that if the serial number field with the "N/A" value was parsed, it would confuse higher-level software because this isn't a unique serial for a device; * 0xFF bytes present in VPD-W field values. Those bytes are not valid values and were probably used by the vendor as placeholders. Ignoring the whole VPD because of that would be too strict. Signed-off-by: Dmitrii Shcherbakov --- src/util/virpcivpd.c | 9 ++-- tests/virpcivpdtest.c | 105 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 102 insertions(+), 12 deletions(-) diff --git a/src/util/virpcivpd.c b/src/util/virpcivpd.c index cd49031fa4..8c2b17c3a6 100644 --- a/src/util/virpcivpd.c +++ b/src/util/virpcivpd.c @@ -544,9 +544,12 @@ virPCIVPDParseVPDLargeResourceFields(int vpdFileFd, ui= nt16_t resPos, uint16_t re */ fieldValue =3D g_strstrip(g_strndup((char *)buf, fieldDataLen)= ); if (!virPCIVPDResourceIsValidTextValue(fieldValue)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Field value contains invalid characters"= )); - return false; + /* Skip fields with invalid values - this is safe assuming= field length is + * correctly specified. */ + VIR_DEBUG("A value for field %s contains invalid character= s", fieldKeyword); + g_free(g_steal_pointer(&fieldKeyword)); + g_free(g_steal_pointer(&fieldValue)); + continue; } } else if (fieldFormat =3D=3D VIR_PCI_VPD_RESOURCE_FIELD_VALUE_FOR= MAT_RESVD) { if (*csum) { diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index 00e34cc94a..b56f335fab 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -692,6 +692,99 @@ testVirPCIVPDParseFullVPDSkipInvalidKeywords(const voi= d *opaque G_GNUC_UNUSED) return 0; } =20 +static int +testVirPCIVPDParseFullVPDSkipInvalidValues(const void *opaque G_GNUC_UNUSE= D) +{ + int fd =3D -1; + size_t dataLen =3D 0; + size_t i =3D 0; + virPCIVPDResourceCustom *custom =3D NULL; + + g_autoptr(virPCIVPDResource) res =3D NULL; + + /* This example is based on real-world hardware which was programmed b= y the vendor with + * invalid field values in both the RO section and RW section. The RO = section contains + * only fields with invalid values and the checksum field with a corre= ct checksum. The + * RW field has a 0 length which means there is no more space in the R= W section. */ + const uint8_t fullVPDExample[] =3D { + 0x82, 0x23, 0x00, 0x48, 0x50, 0x20, 0x45, 0x74, 0x68, 0x65, 0x72, = 0x6e, 0x65, 0x74, + 0x20, 0x31, 0x47, 0x62, 0x20, 0x32, 0x2d, 0x70, 0x6f, 0x72, 0x74, = 0x20, 0x33, 0x36, + 0x31, 0x69, 0x20, 0x41, 0x64, 0x61, 0x70, 0x74, 0x65, 0x72, 0x90, = 0x42, 0x00, 0x50, + 0x4e, 0x03, 0x4e, 0x2f, 0x41, 0x45, 0x43, 0x03, 0x4e, 0x2f, 0x41, = 0x53, 0x4e, 0x03, + 0x4e, 0x2f, 0x41, 0x56, 0x30, 0x29, 0x34, 0x57, 0x2f, 0x31, 0x57, = 0x20, 0x50, 0x43, + 0x49, 0x65, 0x47, 0x32, 0x78, 0x34, 0x20, 0x32, 0x70, 0x20, 0x31, = 0x47, 0x62, 0x45, + 0x20, 0x52, 0x4a, 0x34, 0x35, 0x20, 0x49, 0x6e, 0x74, 0x65, 0x6c, = 0x20, 0x69, 0x33, + 0x35, 0x30, 0x20, 0x20, 0x20, 0x52, 0x56, 0x01, 0x63, 0x91, 0x47, = 0x00, 0x56, 0x31, + 0x06, 0x35, 0x2e, 0x37, 0x2e, 0x30, 0x36, 0x56, 0x33, 0x06, 0x32, = 0x2e, 0x38, 0x2e, + 0x32, 0x30, 0x56, 0x36, 0x06, 0x31, 0x2e, 0x35, 0x2e, 0x33, 0x35, = 0x59, 0x41, 0x03, + 0x4e, 0x2f, 0x41, 0x59, 0x42, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, = 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x59, 0x43, 0x0D, = 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 'R', '= W', 0x00, 0x78, + }; + + dataLen =3D sizeof(fullVPDExample) / sizeof(uint8_t); + fd =3D virCreateAnonymousFile(fullVPDExample, dataLen); + res =3D virPCIVPDParse(fd); + VIR_FORCE_CLOSE(fd); + + if (!res) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "The resource pointer is NULL after parsing which i= s unexpected."); + return -1; + } + /* In this case none of the RO fields have valid contents, however, th= ey have been checksummed + * correctly. Therefore, the RO portion of the resource is not initial= ized. The checksum + * includes bytes of the device name besides the VPD-R section. So thi= s example is valid + * and, considering the parser is implemented to be graceful about inv= alid keywords and + * values, this situation is generally possible. */ + if (res->ro) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "The RO section consisting of only invalid fields g= ot parsed successfully"); + return -1; + } + if (!res->rw) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Could not successfully parse an RW section with so= me invalid fields"); + return -1; + } + + if (res->rw->asset_tag) { + /* The asset tag has an invalid value in this case so it should be= NULL. */ + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Successfully parsed an invalid asset tag."); + return -1; + } + if (res->rw->vendor_specific->len !=3D 3) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "The number of parsed vendor fields is not equal to= the expected number."); + return -1; + } + if (res->rw->system_specific->len > 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "Successfully parsed some systems-specific fields w= hile none are valid"); + return -1; + } + for (i =3D 0; i < res->rw->vendor_specific->len; ++i) { + custom =3D ((virPCIVPDResourceCustom*)g_ptr_array_index(res->rw->v= endor_specific, i)); + if (custom->idx =3D=3D '1') { + if (STRNEQ(custom->value, "5.7.06")) { + return -1; + } + } else if (custom->idx =3D=3D '3') { + if (STRNEQ(custom->value, "2.8.20")) { + return -1; + } + } else if (custom->idx =3D=3D '6') { + if (STRNEQ(custom->value, "1.5.35")) { + return -1; + } + } + } + + return 0; +} + + static int testVirPCIVPDParseFullVPDInvalid(const void *opaque G_GNUC_UNUSED) { @@ -753,14 +846,6 @@ testVirPCIVPDParseFullVPDInvalid(const void *opaque G_= GNUC_UNUSED) 'R', 'V', 0x02, 0x81, 0x00, \ PCI_VPD_RESOURCE_END_VAL =20 -# define VPD_R_INVALID_FIELD_VALUE \ - VPD_STRING_RESOURCE_EXAMPLE_HEADER, \ - VPD_STRING_RESOURCE_EXAMPLE_DATA, \ - PCI_VPD_LARGE_RESOURCE_FLAG | PCI_VPD_READ_ONLY_LARGE_RESOURCE_FLAG, 0= x0A, 0x00, \ - 'S', 'N', 0x02, 0x04, 0x02, \ - 'R', 'V', 0x02, 0x28, 0x00, \ - PCI_VPD_RESOURCE_END_VAL - # define VPD_INVALID_STRING_RESOURCE_VALUE \ VPD_STRING_RESOURCE_EXAMPLE_HEADER, \ 't', 0x03, 's', 't', 'n', 'a', 'm', 'e', \ @@ -833,7 +918,6 @@ testVirPCIVPDParseFullVPDInvalid(const void *opaque G_G= NUC_UNUSED) TEST_INVALID_VPD(VPD_R_INVALID_RV); TEST_INVALID_VPD(VPD_R_INVALID_RV_ZERO_LENGTH); TEST_INVALID_VPD(VPD_R_UNEXPECTED_RW_IN_VPD_R_KEY); - TEST_INVALID_VPD(VPD_R_INVALID_FIELD_VALUE); TEST_INVALID_VPD(VPD_INVALID_STRING_RESOURCE_VALUE); TEST_INVALID_VPD(VPD_INVALID_SN_FIELD_LENGTH); TEST_INVALID_VPD(VPD_INVALID_RV_NOT_LAST); @@ -868,6 +952,9 @@ mymain(void) if (virTestRun("Parsing a VPD resource with a zero-length RW ", testVirPCIVPDParseZeroLengthRW, NULL) < 0) ret =3D -1; + if (virTestRun("Parsing a VPD resource with an invalid values ", + testVirPCIVPDParseFullVPDSkipInvalidValues, NULL) < 0) + ret =3D -1; if (virTestRun("Parsing a VPD resource with an invalid keyword ", testVirPCIVPDParseFullVPDSkipInvalidKeywords, NULL) < 0) ret =3D -1; --=20 2.32.0 From nobody Fri May 3 23:07:19 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=canonical.com 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 1634906769971526.8832103081032; Fri, 22 Oct 2021 05:46:09 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-288-Xkbm3uLPOAm8WwxtCd5MIw-1; Fri, 22 Oct 2021 08:46:05 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4CA605074B; Fri, 22 Oct 2021 12:46: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 9C5F560C13; Fri, 22 Oct 2021 12:45:59 +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 3210A4E9F5; Fri, 22 Oct 2021 12:45:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 19MCjtRO011539 for ; Fri, 22 Oct 2021 08:45:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id E8A4A2166B2F; Fri, 22 Oct 2021 12:45:54 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E35952166B25 for ; Fri, 22 Oct 2021 12:45:52 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1B735800B24 for ; Fri, 22 Oct 2021 12:45:52 +0000 (UTC) Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-427-fsQinouCPk--niZrZbUG6g-1; Fri, 22 Oct 2021 08:45:50 -0400 Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 1E70E40010 for ; Fri, 22 Oct 2021 12:45:49 +0000 (UTC) Received: by mail-lf1-f72.google.com with SMTP id p10-20020a056512234a00b003fe188e9960so1660520lfu.19 for ; Fri, 22 Oct 2021 05:45:49 -0700 (PDT) Received: from ws.lan.d-node.is ([95.165.29.203]) by smtp.gmail.com with ESMTPSA id e8sm722655lft.308.2021.10.22.05.45.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Oct 2021 05:45:48 -0700 (PDT) X-MC-Unique: Xkbm3uLPOAm8WwxtCd5MIw-1 X-MC-Unique: fsQinouCPk--niZrZbUG6g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GddVZV7a2+p5qUXGinVwvjKyXueUKNNFgLsFv3xLmBI=; b=XFJhrAfJphXTR4SiebIO40geqzeaD7eBfXo0+Z6bFF6JusP+MfbmRYdL6SfwhYKJQa kD1jKEE+uQl98/4/SS3JX350Wafq1Kfk/UoeP9Uzf0mdYFOWcmpjW2R0gPF+EcSJ1r1d rsFvIFmwHYFlnKHOHufJJCa6hbCtAC+sgBnga54AfuEhSl5nzSUye7ybsFtAXZdozCVT EfUgQq2vjFsSTmEAXDVSAANgYs+ietmxQ6EaMGa8V1xFe2adXPeqD7cZJOLDb1CUCwrM SjGKbIx6Q+agJ2HvAPEy4IRCdrBiELOsZYqbforsVskesDdl+SXN15ye5ETk1Rl+9Lbi aFJg== X-Gm-Message-State: AOAM531LuvyaUysxSuErVtudcenmuCaQ0zGTJ5nciM8kR5fbuXd1uXkp tQGCzjGTYhp914MILDCmu2wDaArLYf10v41PTKN6MVN7tpxyO95+ccg19eHiLiZeOyA5uls7eGb m5cZ1w0iFrCLxjXRI6tLQCTQsHF5Z49VCIA== X-Received: by 2002:a2e:bd03:: with SMTP id n3mr12799477ljq.165.1634906748536; Fri, 22 Oct 2021 05:45:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxyefD1RWqQwojpSP+wyVrDe50m6dePPgDhCD3r9r7gLUwBa6MXXUFfK6G/0EIyM7QFR1wXQ== X-Received: by 2002:a2e:bd03:: with SMTP id n3mr12799460ljq.165.1634906748361; Fri, 22 Oct 2021 05:45:48 -0700 (PDT) From: Dmitrii Shcherbakov To: dmitrii.shcherbakov@canonical.com, libvir-list@redhat.com Subject: [libvirt PATCH 4/4] PCI VPD: Fix a wrong return code in a test case Date: Fri, 22 Oct 2021 15:45:45 +0300 Message-Id: <20211022124545.412352-5-dmitrii.shcherbakov@canonical.com> In-Reply-To: <20211022124545.412352-1-dmitrii.shcherbakov@canonical.com> References: <20211022124545.412352-1-dmitrii.shcherbakov@canonical.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 19MCjtRO011539 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.12 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-ZM-MESSAGEID: 1634906772333100001 Content-Type: text/plain; charset="utf-8" The test case should return -1, not 0 in case a valid resource could not be parsed successfully but the ret value is initialized to 0. Signed-off-by: Dmitrii Shcherbakov --- tests/virpcivpdtest.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/virpcivpdtest.c b/tests/virpcivpdtest.c index b56f335fab..a4e9b2d0e6 100644 --- a/tests/virpcivpdtest.c +++ b/tests/virpcivpdtest.c @@ -535,7 +535,6 @@ testVirPCIVPDParseFullVPD(const void *opaque G_GNUC_UNU= SED) { int fd =3D -1; size_t dataLen =3D 0; - int ret =3D 0; =20 g_autoptr(virPCIVPDResource) res =3D NULL; /* Note: Custom fields are supposed to be freed by the resource cleanu= p code. */ @@ -556,7 +555,7 @@ testVirPCIVPDParseFullVPD(const void *opaque G_GNUC_UNU= SED) if (!res) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "The resource pointer is NULL after parsing which i= s unexpected"); - return ret; + return -1; } =20 if (!res->ro) { @@ -594,7 +593,7 @@ testVirPCIVPDParseFullVPD(const void *opaque G_GNUC_UNU= SED) return -1; =20 custom =3D NULL; - return ret; + return 0; } =20 static int --=20 2.32.0