From 8b915afa8a2e89bd421d31b0a375d04fcf37edaa Mon Sep 17 00:00:00 2001 From: des Date: Thu, 18 Aug 2005 11:11:40 +0000 Subject: Use larger buffers to read lines from the vendor list. Trim trailing whitespace and comments before parsing, and skip empty lines. Skip subvendor / subdevice entries (which start with two tab characters). Change the scanf() format string to match any amount and type of whitespace between the device ID and the description text. MFC after: 3 weeks --- usr.sbin/pciconf/pciconf.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/pciconf/pciconf.c b/usr.sbin/pciconf/pciconf.c index 828eb85..8fc3146 100644 --- a/usr.sbin/pciconf/pciconf.c +++ b/usr.sbin/pciconf/pciconf.c @@ -369,7 +369,8 @@ load_vendors(void) FILE *db; struct pci_vendor_info *cv; struct pci_device_info *cd; - char buf[100], str[100]; + char buf[1024], str[1024]; + char *ch; int id, error; /* @@ -391,8 +392,20 @@ load_vendors(void) if (fgets(buf, sizeof(buf), db) == NULL) break; + if ((ch = strchr(buf, '#')) != NULL) + *ch = '\0'; + ch = strchr(buf, '\0') - 1; + while (ch > buf && isspace(*ch)) + *ch-- = '\0'; + if (ch <= buf) + continue; + + /* Can't handle subvendor / subdevice entries yet */ + if (buf[0] == '\t' && buf[1] == '\t') + continue; + /* Check for vendor entry */ - if ((buf[0] != '\t') && (sscanf(buf, "%04x\t%[^\n]", &id, str) == 2)) { + if (buf[0] != '\t' && sscanf(buf, "%04x %[^\n]", &id, str) == 2) { if ((id == 0) || (strlen(str) < 1)) continue; if ((cv = malloc(sizeof(struct pci_vendor_info))) == NULL) { @@ -413,7 +426,7 @@ load_vendors(void) } /* Check for device entry */ - if ((buf[0] == '\t') && (sscanf(buf + 1, "%04x\t%[^\n]", &id, str) == 2)) { + if (buf[0] == '\t' && sscanf(buf + 1, "%04x %[^\n]", &id, str) == 2) { if ((id == 0) || (strlen(str) < 1)) continue; if (cv == NULL) { -- cgit v1.1