summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoan Lledó <jlledom@member.fsf.org>2019-11-24 20:47:45 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2019-11-24 20:51:39 +0100
commitf0b177197381359ff2cb1799640244817fd3b3db (patch)
treec00dbfee930c91f37435dea03eaf220ecad7a21f
parent6b1312cfbb77dfe338f56a71a8f5461ec135f47c (diff)
pci-arbiter: Fix memory bugs
* pci-arbiter/pcifs.c: * init_file_system: Remove unnecessary free() * create_fs_tree: Fix a boundary overrun where no devices are found. Message-Id: <20191124194721.4982-2-jlledom@mailfence.com>
-rw-r--r--pci-arbiter/pcifs.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/pci-arbiter/pcifs.c b/pci-arbiter/pcifs.c
index aaee7f0b..d19fc618 100644
--- a/pci-arbiter/pcifs.c
+++ b/pci-arbiter/pcifs.c
@@ -115,7 +115,6 @@ init_file_system (file_t underlying_node, struct pcifs * fs)
fs->entries = calloc (1, sizeof (struct pcifs_dirent));
if (!fs->entries)
{
- free (fs->entries);
return ENOMEM;
}
@@ -189,6 +188,12 @@ create_fs_tree (struct pcifs * fs)
pci_iterator_destroy(iter);
+ if (nentries == 1)
+ {
+ /* No devices found, no need to continue */
+ return 0;
+ }
+
list = realloc (fs->entries, nentries * sizeof (struct pcifs_dirent));
if (!list)
return ENOMEM;