aboutsummaryrefslogtreecommitdiff
path: root/contrib/elf2dmp/pdb.c
diff options
context:
space:
mode:
authorViktor Prutyanov <viktor@daynix.com>2023-10-01 02:53:17 +0300
committerPeter Maydell <peter.maydell@linaro.org>2023-10-19 14:32:12 +0100
commit9d9c06b144da340b9a937ed01d45a936810715be (patch)
treeef495b15f63fc8bd5d0540aff181cebafb7d1a9f /contrib/elf2dmp/pdb.c
parent8b01683e857a80425ea67dc44505b4983fc11a8e (diff)
downloadqemu-9d9c06b144da340b9a937ed01d45a936810715be.zip
qemu-9d9c06b144da340b9a937ed01d45a936810715be.tar.gz
qemu-9d9c06b144da340b9a937ed01d45a936810715be.tar.bz2
elf2dmp: check array bounds in pdb_get_file_size
Index in file_size array must be checked against num_files, because the entries we are looking for may be absent in the PDB. Fixes: Coverity CID 1521597 Signed-off-by: Viktor Prutyanov <viktor@daynix.com> Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-id: 20230930235317.11469-3-viktor@daynix.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'contrib/elf2dmp/pdb.c')
-rw-r--r--contrib/elf2dmp/pdb.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c
index 6ca5086..8e3c18c 100644
--- a/contrib/elf2dmp/pdb.c
+++ b/contrib/elf2dmp/pdb.c
@@ -25,6 +25,10 @@
static uint32_t pdb_get_file_size(const struct pdb_reader *r, unsigned idx)
{
+ if (idx >= r->ds.toc->num_files) {
+ return 0;
+ }
+
return r->ds.toc->file_size[idx];
}
@@ -159,16 +163,17 @@ static void *pdb_ds_read_file(struct pdb_reader* r, uint32_t file_number)
static int pdb_init_segments(struct pdb_reader *r)
{
- char *segs;
unsigned stream_idx = r->segments;
- segs = pdb_ds_read_file(r, stream_idx);
- if (!segs) {
+ r->segs = pdb_ds_read_file(r, stream_idx);
+ if (!r->segs) {
return 1;
}
- r->segs = segs;
r->segs_size = pdb_get_file_size(r, stream_idx);
+ if (!r->segs_size) {
+ return 1;
+ }
return 0;
}