From: Martin Mares Date: Tue, 23 Aug 2005 19:56:45 +0000 (+0000) Subject: Improved reading of dumps X-Git-Tag: v3.0.0~90 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=f7821e53a17303c2587b7aa053c5b3e8d70cf628;p=pciutils.git Improved reading of dumps git-archimport-id: mj@ucw.cz--public/pciutils--main--2.2--patch-75 --- diff --git a/ChangeLog b/ChangeLog index 9c5973e..e43ed8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,7 +13,9 @@ device has either PCI-X or PCI Express capability in its normal capability list. - * lib/dump.c (dump_init): Reading of dumps works again. + * lib/dump.c (dump_init): Reading of dumps works again. The dump reader + now also remembers how much data it has read and refuses attempts to + access more than that. * setpci.man, lspci.c, README: prefer spelling "buses" over "busses". diff --git a/lib/dump.c b/lib/dump.c index 5a5b50e..32a6ace 100644 --- a/lib/dump.c +++ b/lib/dump.c @@ -1,7 +1,7 @@ /* * The PCI Library -- Reading of Bus Dumps * - * Copyright (c) 1997--2004 Martin Mares + * Copyright (c) 1997--2005 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -14,7 +14,7 @@ #include "internal.h" struct dump_data { - int len; + int len, allocated; byte data[1]; }; @@ -28,7 +28,8 @@ static void dump_alloc_data(struct pci_dev *dev, int len) { struct dump_data *dd = pci_malloc(dev->access, sizeof(struct dump_data) + len - 1); - dd->len = len; + dd->allocated = len; + dd->len = 0; memset(dd->data, 0xff, len); dev->aux = dd; } @@ -80,7 +81,7 @@ dump_init(struct pci_access *a) a->error("dump: Malformed line"); if (i >= 4096) break; - if (i > dd->len) /* Need to re-allocate the buffer */ + if (i > dd->allocated) /* Need to re-allocate the buffer */ { dump_alloc_data(dev, 4096); memcpy(((struct dump_data *) dev->aux)->data, dd->data, 256); @@ -88,6 +89,8 @@ dump_init(struct pci_access *a) dd = dev->aux; } dd->data[i++] = j; + if (i > dd->len) + dd->len = i; z += 2; } }