elfxx: store elf image pointer and size after mapping image
If loading debug link is not successful, the initial NULL pointer for
ei->image will eventually be restored, causing segfault during a later
call to valid_object.
Move populating the prev_image and prev_size to after elf_map_image() to
fix this.
@@ -386,8 +386,8 @@ elf_w (load_debuglink) (const char* file, struct elf_image *ei, int is_local)
{
int ret;
Elf_W (Shdr) *shdr;
- Elf_W (Ehdr) *prev_image = ei->image;
- off_t prev_size = ei->size;
+ Elf_W (Ehdr) *prev_image;
+ off_t prev_size;
if (!ei->image)
{
@@ -396,6 +396,9 @@ elf_w (load_debuglink) (const char* file, struct elf_image *ei, int is_local)
return ret;
}
+ prev_image = ei->image;
+ prev_size = ei->size;
+
/* Ignore separate debug files which contain a .gnu_debuglink section. */
if (is_local == -1) {
return 0;
