From nobody Fri Apr 19 09:10:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1520954521687614.3494346372571; Tue, 13 Mar 2018 08:22:01 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id F276D80F8D; Tue, 13 Mar 2018 15:21:59 +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 730C46A043; Tue, 13 Mar 2018 15:21:58 +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 2DDA81806103; Tue, 13 Mar 2018 15:21:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2DFLu2O012256 for ; Tue, 13 Mar 2018 11:21:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 03B881DB27; Tue, 13 Mar 2018 15:21:56 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F12E1C732 for ; Tue, 13 Mar 2018 15:21:53 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 13 Mar 2018 16:21:46 +0100 Message-Id: <46af530542be4867e8899ad2a1bbb10f107c42fe.1520954506.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virsysinfo: Use more virSkipSpacesBackwards() 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 13 Mar 2018 15:22:00 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Some fields reported by dmidecode have plenty of useless spaces (in fact some have nothing but spaces). To deal with this we have introduced virSkipSpacesBackwards() and use it in virSysinfoParseX86Processor() and virSysinfoParseX86Memory(). However, other functions (e.g. virSysinfoParseX86Chassis()) don't use it at all and thus we are reporting nonsense: FUJITSU Default string Signed-off-by: Michal Privoznik --- src/util/virsysinfo.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 43a4c8835..5795d90c7 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -644,7 +644,8 @@ static int virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios) { int ret =3D -1; - const char *cur, *eol =3D NULL; + const char *cur; + char *eol =3D NULL; virSysinfoBIOSDefPtr def; =20 if ((cur =3D strstr(base, "BIOS Information")) =3D=3D NULL) @@ -657,24 +658,28 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSD= efPtr *bios) if ((cur =3D strstr(base, "Vendor: ")) !=3D NULL) { cur +=3D 8; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->vendor, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Version: ")) !=3D NULL) { cur +=3D 9; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Release Date: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->date, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "BIOS Revision: ")) !=3D NULL) { cur +=3D 15; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->release, cur, eol - cur) < 0) goto cleanup; } @@ -697,7 +702,8 @@ static int virSysinfoParseX86System(const char *base, virSysinfoSystemDefPtr *sysdef) { int ret =3D -1; - const char *cur, *eol =3D NULL; + const char *cur; + char *eol =3D NULL; virSysinfoSystemDefPtr def; =20 if ((cur =3D strstr(base, "System Information")) =3D=3D NULL) @@ -710,42 +716,49 @@ virSysinfoParseX86System(const char *base, virSysinfo= SystemDefPtr *sysdef) if ((cur =3D strstr(base, "Manufacturer: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Product Name: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Version: ")) !=3D NULL) { cur +=3D 9; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Serial Number: ")) !=3D NULL) { cur +=3D 15; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "UUID: ")) !=3D NULL) { cur +=3D 6; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->uuid, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "SKU Number: ")) !=3D NULL) { cur +=3D 12; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Family: ")) !=3D NULL) { cur +=3D 8; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0) goto cleanup; } @@ -770,7 +783,8 @@ virSysinfoParseX86BaseBoard(const char *base, size_t *nbaseBoard) { int ret =3D -1; - const char *cur, *eol =3D NULL; + const char *cur; + char *eol =3D NULL; virSysinfoBaseBoardDefPtr boards =3D NULL; size_t nboards =3D 0; char *board_type =3D NULL; @@ -787,36 +801,42 @@ virSysinfoParseX86BaseBoard(const char *base, if ((cur =3D strstr(base, "Manufacturer: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Product Name: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Version: ")) !=3D NULL) { cur +=3D 9; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Serial Number: ")) !=3D NULL) { cur +=3D 15; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Asset Tag: ")) !=3D NULL) { cur +=3D 11; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Location In Chassis: ")) !=3D NULL) { cur +=3D 21; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->location, cur, eol - cur) < 0) goto cleanup; } @@ -848,7 +868,8 @@ virSysinfoParseX86Chassis(const char *base, virSysinfoChassisDefPtr *chassisdef) { int ret =3D -1; - const char *cur, *eol =3D NULL; + const char *cur; + char *eol =3D NULL; virSysinfoChassisDefPtr def; =20 if ((cur =3D strstr(base, "Chassis Information")) =3D=3D NULL) @@ -861,30 +882,35 @@ virSysinfoParseX86Chassis(const char *base, if ((cur =3D strstr(base, "Manufacturer: ")) !=3D NULL) { cur +=3D 14; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Version: ")) !=3D NULL) { cur +=3D 9; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Serial Number: ")) !=3D NULL) { cur +=3D 15; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "Asset Tag: ")) !=3D NULL) { cur +=3D 11; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0) goto cleanup; } if ((cur =3D strstr(base, "SKU Number: ")) !=3D NULL) { cur +=3D 12; eol =3D strchr(cur, '\n'); + virSkipSpacesBackwards(cur, &eol); if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0) goto cleanup; } --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list