Skip to contentSkip to conversation

pmdinfogen: Resolve coverity scan forward null issue

PATCH Applied Neil Horman 2 participants 2 messages Jan 5, 2017 – Jan 6, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pmdinfogen: Resolve coverity scan forward null issue

From: Neil Horman <[email protected]>

Coverity issue 139593 reports a forward null dereference from a for loop that works with a variable previously tested for null that had no error handling or condition to prevent it. Pretty obvious fix below.

---
 buildtools/pmdinfogen/pmdinfogen.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
buildtools/pmdinfogen/pmdinfogen.c +8 -7
index 5129c57..ba1a12e 100644
@@ -226,13 +226,14 @@ static int parse_elf(struct elf_info *info, const char *filename)
 	}
 	if (!info->symtab_start)
 		fprintf(stderr, "%s has no symtab?\n", filename);
-
-	/* Fix endianness in symbols */
-	for (sym = info->symtab_start; sym < info->symtab_stop; sym++) {
-		sym->st_shndx = TO_NATIVE(endian, 16, sym->st_shndx);
-		sym->st_name  = TO_NATIVE(endian, 32, sym->st_name);
-		sym->st_value = TO_NATIVE(endian, ADDR_SIZE, sym->st_value);
-		sym->st_size  = TO_NATIVE(endian, ADDR_SIZE, sym->st_size);
+	else {
+		/* Fix endianness in symbols */
+		for (sym = info->symtab_start; sym < info->symtab_stop; sym++) {
+			sym->st_shndx = TO_NATIVE(endian, 16, sym->st_shndx);
+			sym->st_name  = TO_NATIVE(endian, 32, sym->st_name);
+			sym->st_value = TO_NATIVE(endian, ADDR_SIZE, sym->st_value);
+			sym->st_size  = TO_NATIVE(endian, ADDR_SIZE, sym->st_size);
+		}
 	}
 
 	if (symtab_shndx_idx != ~0U) {
Signature · 1 line
2.9.3
#1 lore raw

2017-01-05 14:22, Neil Horman:

Quoted 7 lines

From: Neil Horman <[email protected]>

Coverity issue 139593 reports a forward null dereference from a for loop that works with a variable previously tested for null that had no error handling or condition to prevent it. Pretty obvious fix below.

Coverity issue: 139593

Fixes 98b0fdb0ffc6 ("pmdinfogen: add buildtools and pmdinfogen utility")

Applied, thanks