X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fdump.c;h=8b7320a05ba83feccb51569d46c0f4ff47fc8cff;hb=8a5d293fb78ca42a969df9e2b617456391636596;hp=0196f6998cdd1ee838d19343242c424d8fdc1a8f;hpb=52c815195259cc9d388fac44ead8191de7d24c76;p=pciutils.git diff --git a/lib/dump.c b/lib/dump.c index 0196f69..8b7320a 100644 --- a/lib/dump.c +++ b/lib/dump.c @@ -3,7 +3,9 @@ * * Copyright (c) 1997--2008 Martin Mares * - * Can be freely distributed and used under the terms of the GNU GPL. + * Can be freely distributed and used under the terms of the GNU GPL v2+. + * + * SPDX-License-Identifier: GPL-2.0-or-later */ #include @@ -62,7 +64,7 @@ dump_init(struct pci_access *a) struct pci_dev *dev = NULL; int len, mn, bn, dn, fn, i, j; - if (!a) + if (!name) a->error("dump: File name not given."); if (!(f = fopen(name, "r"))) a->error("dump: Cannot open %s: %s", name, strerror(errno)); @@ -70,14 +72,18 @@ dump_init(struct pci_access *a) { char *z = strchr(buf, '\n'); if (!z) - a->error("dump: line too long or unterminated"); + { + fclose(f); + a->error("dump: line too long or unterminated"); + } *z-- = 0; if (z >= buf && *z == '\r') *z-- = 0; len = z - buf + 1; mn = 0; if (dump_validate(buf, "##:##.# ") && sscanf(buf, "%x:%x.%d", &bn, &dn, &fn) == 3 || - dump_validate(buf, "####:##:##.# ") && sscanf(buf, "%x:%x:%x.%d", &mn, &bn, &dn, &fn) == 4) + dump_validate(buf, "####:##:##.# ") && sscanf(buf, "%x:%x:%x.%d", &mn, &bn, &dn, &fn) == 4 || + dump_validate(buf, "#####:##:##.# ") && sscanf(buf, "%x:%x:%x.%d", &mn, &bn, &dn, &fn) == 4) { dev = pci_get_dev(a, mn, bn, dn, fn); dump_alloc_data(dev, 256); @@ -86,7 +92,9 @@ dump_init(struct pci_access *a) else if (!len) dev = NULL; else if (dev && - (dump_validate(buf, "##: ") || dump_validate(buf, "###: ")) && + (dump_validate(buf, "##: ") || dump_validate(buf, "###: ") || dump_validate(buf, "####: ") || + dump_validate(buf, "#####: ") || dump_validate(buf, "######: ") || + dump_validate(buf, "#######: ") || dump_validate(buf, "########: ")) && sscanf(buf, "%x: ", &i) == 1) { struct dump_data *dd = dev->aux; @@ -95,7 +103,10 @@ dump_init(struct pci_access *a) sscanf(z, "%x", &j) == 1 && j < 256) { if (i >= 4096) - a->error("dump: At most 4096 bytes of config space are supported"); + { + fclose(f); + a->error("dump: At most 4096 bytes of config space are supported"); + } if (i >= dd->allocated) /* Need to re-allocate the buffer */ { dump_alloc_data(dev, 4096); @@ -111,9 +122,13 @@ dump_init(struct pci_access *a) z++; } if (*z) - a->error("dump: Malformed line"); + { + fclose(f); + a->error("dump: Malformed line"); + } } } + fclose(f); } static void