Skip to contentSkip to conversation

elf2dmp: fixes of code analysis warnings

PATCH Superseded Viktor Prutyanov 1 participant 3 messages Sep 30, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover elf2dmp: fixes of code analysis warnings

This series is dedicated to fixes of Coverity warnings.

Viktor Prutyanov (2):
elf2dmp: limit print length for sign_rsds
elf2dmp: check array bounds in pdb_get_file_size

 contrib/elf2dmp/main.c |  2 +-
 contrib/elf2dmp/pdb.c  | 13 +++++++++----
 2 files changed, 10 insertions(+), 5 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/2 elf2dmp: limit print length for sign_rsds

From: Viktor Prutyanov <[email protected]>

String sign_rsds isn't terminated, so the print length must be limited.

---
 contrib/elf2dmp/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/elf2dmp/main.c +1 -1
index 5db163bdbe..6de5c9808e 100644
@@ -478,7 +478,7 @@ static bool pe_check_pdb_name(uint64_t base, void *start_addr,
     }
 
     if (memcmp(&rsds->Signature, sign_rsds, sizeof(sign_rsds))) {
-        eprintf("CodeView signature is \'%.4s\', \'%s\' expected\n",
+        eprintf("CodeView signature is \'%.4s\', \'%.4s\' expected\n",
                 rsds->Signature, sign_rsds);
         return false;
     }
Signature · 1 line
2.21.0
#2 lore raw

PATCH 2/2 elf2dmp: check array bounds in pdb_get_file_size

In reply to Viktor Prutyanov

Index in file_size array must be checked against num_files, because the entries we are looking for may be absent in the PDB.

---
 contrib/elf2dmp/pdb.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
contrib/elf2dmp/pdb.c +9 -4
index 6ca5086f02..8e3c18c82f 100644
@@ -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;
 }
Signature · 1 line
2.21.0