summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2005-08-18 11:11:40 +0000
committerdes <des@FreeBSD.org>2005-08-18 11:11:40 +0000
commit8b915afa8a2e89bd421d31b0a375d04fcf37edaa (patch)
treed9efeb8fe5806e92404bdd52494116f96de02ae7 /usr.sbin
parent1dd6384f2b469c080a78b5e3e47d7a341733de1e (diff)
downloadFreeBSD-src-8b915afa8a2e89bd421d31b0a375d04fcf37edaa.zip
FreeBSD-src-8b915afa8a2e89bd421d31b0a375d04fcf37edaa.tar.gz
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
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pciconf/pciconf.c19
1 files changed, 16 insertions, 3 deletions
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) {
OpenPOWER on IntegriCloud