Skip to content

Commit

Permalink
(AB): Also check for writable and executable segments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Drepper committed Jan 9, 2006
1 parent 8dd1843 commit 3ca66a2
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions elf/check-textrel.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Check for text relocations in DSOs.
Copyright (C) 2002, 2003 Free Software Foundation, Inc.
Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contribute by Ulrich Drepper <drepper@redhat.com>. 2002.
Expand Down Expand Up @@ -79,20 +79,28 @@ AB(handle_file) (const char *fname, int fd)

/* Search for the PT_DYNAMIC entry. */
size_t cnt;
E(Phdr) *dynphdr = NULL;
for (cnt = 0; cnt < phnum; ++cnt)
if (SWAP (phdr[cnt].p_type) == PT_DYNAMIC)
break;

if (cnt == phnum)
dynphdr = &phdr[cnt];
else if (SWAP (phdr[cnt].p_type) == PT_LOAD
&& (SWAP (phdr[cnt].p_flags) & (PF_X | PF_W)) == (PF_X | PF_W))
{
printf ("%s: segment %zu is executable and writable\n",
fname);
return 1;
}

if (dynphdr == NULL)
{
printf ("%s: no DYNAMIC segment found\n", fname);
return 1;
}

/* Read the dynamic segment. */
size_t pmemsz = SWAP(phdr[cnt].p_memsz);
size_t pmemsz = SWAP(dynphdr->p_memsz);
E(Dyn) *dyn = alloca (pmemsz);
if (pread (fd, dyn, pmemsz, SWAP(phdr[cnt].p_offset)) != pmemsz)
if (pread (fd, dyn, pmemsz, SWAP(dynphdr->p_offset)) != pmemsz)
goto read_error;

/* Search for an DT_TEXTREL entry of DT_FLAGS with the DF_TEXTREL
Expand Down

0 comments on commit 3ca66a2

Please sign in to comment.