[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
readelf [PATCH]
From: |
Sergei Pachkov |
Subject: |
readelf [PATCH] |
Date: |
Mon, 04 Nov 2002 15:34:06 +0300 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2b) Gecko/20021016 |
Hello.
I have found a little bug in "readelf" this weekend.
Sometimes variable called "process_headers" may have NULL value and its
members reading would be failed.
For avoid this problem I have wrote little patch.
In the patch I have add few checks of variable process_headers like this:
if (process_headers != NULL)
or
if (process_headers == NULL)
--- readelf.c.orig Mon Nov 4 12:15:56 2002
+++ readelf.c Mon Nov 4 12:29:32 2002
@@ -354,15 +354,21 @@ get_data (var, file, offset, size, reaso
const char *reason;
{
PTR mvar;
-
+ int err;
+ int c;
+
if (size == 0)
return NULL;
- if (fseek (file, offset, SEEK_SET))
+ err = fseek (file, offset, SEEK_SET);
+ Ó = getc(file);
+
+ if ((Ó == EOF) || (err != 0))
{
error (_("Unable to seek to %x for %s\n"), offset, reason);
return NULL;
}
+ ungetc(Ó,file); /* push C back to stream */
mvar = var;
if (mvar == NULL)
@@ -3444,6 +3450,10 @@ process_section_headers (file)
dynamic_syminfo = NULL;
symtab_shndx_hdr = NULL;
+ if (section_headers != NULL) /* sometimes section_headers may be NULL,
+ i.e. when section offset is wrong or
+ allocation memory space for section_headers
has been failed. */
+{
for (i = 0, section = section_headers;
i < elf_header.e_shnum;
i ++, section ++)
@@ -3511,7 +3521,7 @@ process_section_headers (file)
else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
request_dump (i, DEBUG_DUMP);
}
-
+}
if (! do_sections)
return 1;
@@ -3532,6 +3542,9 @@ process_section_headers (file)
printf (_(" Size EntSize Flags Link Info
Align\n"));
}
+if (section_headers != NULL)
+{
+
for (i = 0, section = section_headers;
i < elf_header.e_shnum;
i ++, section ++)
@@ -3623,7 +3636,7 @@ process_section_headers (file)
(unsigned long) section->sh_addralign);
}
}
-
+}
printf (_("Key to Flags:\n\
W (write), A (alloc), X (execute), M (merge), S (strings)\n\
I (info), L (link order), G (group), x (unknown)\n\
@@ -3699,7 +3712,8 @@ process_relocs (file)
Elf32_Internal_Shdr * section;
unsigned long i;
int found = 0;
-
+if (section_headers != NULL)
+{
for (i = 0, section = section_headers;
i < elf_header.e_shnum;
i++, section ++)
@@ -3762,7 +3776,7 @@ process_relocs (file)
found = 1;
}
}
-
+}
if (! found)
printf (_("\nThere are no relocations in this file.\n"));
}
@@ -3989,7 +4003,6 @@ slurp_ia64_unwind_table (file, aux, sec)
free (table);
/* Third, apply any relocations to the unwind table: */
-
for (relsec = section_headers;
relsec < section_headers + elf_header.e_shnum;
++relsec)
@@ -4058,7 +4071,6 @@ slurp_ia64_unwind_table (file, aux, sec)
free (rela);
}
-
aux->table_len = size / (3 * addr_size);
return 1;
}
@@ -4083,7 +4095,8 @@ process_unwind (file)
memset (& aux, 0, sizeof (aux));
addr_size = is_32bit_elf ? 4 : 8;
-
+if (section_headers != NULL)
+{
for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
{
if (sec->sh_type == SHT_SYMTAB)
@@ -4190,7 +4203,7 @@ process_unwind (file)
aux.info = NULL;
}
}
-
+}
if (aux.symtab)
free (aux.symtab);
if (aux.strtab)
@@ -5031,7 +5044,8 @@ process_version_sections (file)
if (! do_version)
return 1;
-
+if (section_headers != NULL)
+{
for (i = 0, section = section_headers;
i < elf_header.e_shnum;
i++, section ++)
@@ -5420,6 +5434,7 @@ process_version_sections (file)
break;
}
}
+}
if (! found)
printf (_("\nNo version information found in this file.\n"));
@@ -5662,7 +5677,8 @@ process_symbol_table (file)
else if (do_syms && !do_using_dynamic)
{
unsigned int i;
-
+if (section_headers != NULL)
+{
for (i = 0, section = section_headers;
i < elf_header.e_shnum;
i++, section++)
@@ -5853,6 +5869,7 @@ process_symbol_table (file)
if (strtab != string_table)
free (strtab);
}
+}
}
else if (do_syms)
printf
@@ -9077,6 +9094,7 @@ process_section_contents (file)
if (! do_dump)
return 1;
+if (section_headers == NULL) return 1;
/* Pre-scan the debug sections to find some debug information not
present in some of them. For the .debug_line, we must find out the
@@ -9558,6 +9576,7 @@ process_gnu_liblist (file)
if (! do_arch)
return 0;
+if (section_headers == NULL) return 0;
for (i = 0, section = section_headers;
i < elf_header.e_shnum;
- readelf [PATCH],
Sergei Pachkov <=