virsysinfo: Use more virSkipSpacesBackwards()

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:

  <sysinfo type='smbios'>
    <chassis>
      <entry name='manufacturer'>FUJITSU</entry>
      <entry name='version'>                      </entry>
      <entry name='serial'>                </entry>
      <entry name='asset'>                                        </entry>
      <entry name='sku'>Default string</entry>
    </chassis>
  </sysinfo>

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2018-03-13 16:03:13 +01:00
parent 5433ec02ad
commit bc01d903c2
2 changed files with 31 additions and 5 deletions

View File

@ -644,7 +644,8 @@ static int
virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios) virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios)
{ {
int ret = -1; int ret = -1;
const char *cur, *eol = NULL; const char *cur;
char *eol = NULL;
virSysinfoBIOSDefPtr def; virSysinfoBIOSDefPtr def;
if ((cur = strstr(base, "BIOS Information")) == NULL) if ((cur = strstr(base, "BIOS Information")) == NULL)
@ -657,24 +658,28 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios)
if ((cur = strstr(base, "Vendor: ")) != NULL) { if ((cur = strstr(base, "Vendor: ")) != NULL) {
cur += 8; cur += 8;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->vendor, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->vendor, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Version: ")) != NULL) { if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9; cur += 9;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Release Date: ")) != NULL) { if ((cur = strstr(base, "Release Date: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->date, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->date, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "BIOS Revision: ")) != NULL) { if ((cur = strstr(base, "BIOS Revision: ")) != NULL) {
cur += 15; cur += 15;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->release, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->release, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
@ -697,7 +702,8 @@ static int
virSysinfoParseX86System(const char *base, virSysinfoSystemDefPtr *sysdef) virSysinfoParseX86System(const char *base, virSysinfoSystemDefPtr *sysdef)
{ {
int ret = -1; int ret = -1;
const char *cur, *eol = NULL; const char *cur;
char *eol = NULL;
virSysinfoSystemDefPtr def; virSysinfoSystemDefPtr def;
if ((cur = strstr(base, "System Information")) == NULL) if ((cur = strstr(base, "System Information")) == NULL)
@ -710,42 +716,49 @@ virSysinfoParseX86System(const char *base, virSysinfoSystemDefPtr *sysdef)
if ((cur = strstr(base, "Manufacturer: ")) != NULL) { if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Product Name: ")) != NULL) { if ((cur = strstr(base, "Product Name: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Version: ")) != NULL) { if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9; cur += 9;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Serial Number: ")) != NULL) { if ((cur = strstr(base, "Serial Number: ")) != NULL) {
cur += 15; cur += 15;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "UUID: ")) != NULL) { if ((cur = strstr(base, "UUID: ")) != NULL) {
cur += 6; cur += 6;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->uuid, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->uuid, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "SKU Number: ")) != NULL) { if ((cur = strstr(base, "SKU Number: ")) != NULL) {
cur += 12; cur += 12;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Family: ")) != NULL) { if ((cur = strstr(base, "Family: ")) != NULL) {
cur += 8; cur += 8;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
@ -770,7 +783,8 @@ virSysinfoParseX86BaseBoard(const char *base,
size_t *nbaseBoard) size_t *nbaseBoard)
{ {
int ret = -1; int ret = -1;
const char *cur, *eol = NULL; const char *cur;
char *eol = NULL;
virSysinfoBaseBoardDefPtr boards = NULL; virSysinfoBaseBoardDefPtr boards = NULL;
size_t nboards = 0; size_t nboards = 0;
char *board_type = NULL; char *board_type = NULL;
@ -787,36 +801,42 @@ virSysinfoParseX86BaseBoard(const char *base,
if ((cur = strstr(base, "Manufacturer: ")) != NULL) { if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Product Name: ")) != NULL) { if ((cur = strstr(base, "Product Name: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Version: ")) != NULL) { if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9; cur += 9;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Serial Number: ")) != NULL) { if ((cur = strstr(base, "Serial Number: ")) != NULL) {
cur += 15; cur += 15;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Asset Tag: ")) != NULL) { if ((cur = strstr(base, "Asset Tag: ")) != NULL) {
cur += 11; cur += 11;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Location In Chassis: ")) != NULL) { if ((cur = strstr(base, "Location In Chassis: ")) != NULL) {
cur += 21; cur += 21;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->location, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->location, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
@ -848,7 +868,8 @@ virSysinfoParseX86Chassis(const char *base,
virSysinfoChassisDefPtr *chassisdef) virSysinfoChassisDefPtr *chassisdef)
{ {
int ret = -1; int ret = -1;
const char *cur, *eol = NULL; const char *cur;
char *eol = NULL;
virSysinfoChassisDefPtr def; virSysinfoChassisDefPtr def;
if ((cur = strstr(base, "Chassis Information")) == NULL) if ((cur = strstr(base, "Chassis Information")) == NULL)
@ -861,30 +882,35 @@ virSysinfoParseX86Chassis(const char *base,
if ((cur = strstr(base, "Manufacturer: ")) != NULL) { if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
cur += 14; cur += 14;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Version: ")) != NULL) { if ((cur = strstr(base, "Version: ")) != NULL) {
cur += 9; cur += 9;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Serial Number: ")) != NULL) { if ((cur = strstr(base, "Serial Number: ")) != NULL) {
cur += 15; cur += 15;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "Asset Tag: ")) != NULL) { if ((cur = strstr(base, "Asset Tag: ")) != NULL) {
cur += 11; cur += 11;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }
if ((cur = strstr(base, "SKU Number: ")) != NULL) { if ((cur = strstr(base, "SKU Number: ")) != NULL) {
cur += 12; cur += 12;
eol = strchr(cur, '\n'); eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0) if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0)
goto cleanup; goto cleanup;
} }

View File

@ -1,5 +1,5 @@
BIOS Information BIOS Information
Vendor: LENOVO Vendor: LENOVO
Version: 6DET62WW (3.12 ) Version: 6DET62WW (3.12 )
Release Date: 01/12/2010 Release Date: 01/12/2010
Address: 0xE0000 Address: 0xE0000