aboutsummaryrefslogtreecommitdiff
path: root/elf
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2015-04-08 19:11:21 +0200
committerFlorian Weimer <fweimer@redhat.com>2015-04-08 21:06:49 +0200
commit7b8399f479fb9ebaf816a49246ea5c6354a0769e (patch)
tree5911d30a4f985073aaba0d06a8603391113ed686 /elf
parentAdd more tests of cbrt. (diff)
downloadglibc-7b8399f479fb9ebaf816a49246ea5c6354a0769e.tar.gz
glibc-7b8399f479fb9ebaf816a49246ea5c6354a0769e.tar.bz2
glibc-7b8399f479fb9ebaf816a49246ea5c6354a0769e.zip
pldd: Use struct scratch_buffer instead of extend_alloca
Diffstat (limited to 'elf')
-rw-r--r--elf/pldd-xx.c32
-rw-r--r--elf/pldd.c24
2 files changed, 37 insertions, 19 deletions
diff --git a/elf/pldd-xx.c b/elf/pldd-xx.c
index d865739853..2f1962883c 100644
--- a/elf/pldd-xx.c
+++ b/elf/pldd-xx.c
@@ -186,35 +186,43 @@ E(find_maps) (pid_t pid, void *auxv, size_t auxv_size)
printf ("%lu:\t%s\n", (unsigned long int) pid, exe);
/* Iterate over the list of objects and print the information. */
- size_t strsize = 256;
- char *str = alloca (strsize);
+ struct scratch_buffer tmpbuf;
+ scratch_buffer_init (&tmpbuf);
+ int status = 0;
do
{
struct E(link_map) m;
if (pread64 (memfd, &m, sizeof (m), list) != sizeof (m))
{
error (0, 0, gettext ("cannot read link map"));
- return EXIT_FAILURE;
+ status = EXIT_FAILURE;
+ goto out;
}
EW(Addr) name_offset = m.l_name;
again:
while (1)
{
- ssize_t n = pread64 (memfd, str, strsize, name_offset);
+ ssize_t n = pread64 (memfd, tmpbuf.data, tmpbuf.length, name_offset);
if (n == -1)
{
error (0, 0, gettext ("cannot read object name"));
- return EXIT_FAILURE;
+ status = EXIT_FAILURE;
+ goto out;
}
- if (memchr (str, '\0', n) != NULL)
+ if (memchr (tmpbuf.data, '\0', n) != NULL)
break;
- str = extend_alloca (str, strsize, strsize * 2);
+ if (!scratch_buffer_grow (&tmpbuf))
+ {
+ error (0, 0, gettext ("cannot allocate buffer for object name"));
+ status = EXIT_FAILURE;
+ goto out;
+ }
}
- if (str[0] == '\0' && name_offset == m.l_name
+ if (((char *)tmpbuf.data)[0] == '\0' && name_offset == m.l_name
&& m.l_libname != 0)
{
/* Try the l_libname element. */
@@ -227,14 +235,16 @@ E(find_maps) (pid_t pid, void *auxv, size_t auxv_size)
}
/* Skip over the executable. */
- if (str[0] != '\0')
- printf ("%s\n", str);
+ if (((char *)tmpbuf.data)[0] != '\0')
+ printf ("%s\n", (char *)tmpbuf.data);
list = m.l_next;
}
while (list != 0);
- return 0;
+ out:
+ scratch_buffer_free (&tmpbuf);
+ return status;
}
diff --git a/elf/pldd.c b/elf/pldd.c
index 9e1d82244f..2b862248a6 100644
--- a/elf/pldd.c
+++ b/elf/pldd.c
@@ -35,6 +35,7 @@
#include <sys/ptrace.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <scratch_buffer.h>
#include <ldsodefs.h>
#include <version.h>
@@ -118,18 +119,25 @@ main (int argc, char *argv[])
if (dfd == -1)
error (EXIT_FAILURE, errno, gettext ("cannot open %s"), buf);
- size_t exesize = 1024;
-#ifdef PATH_MAX
- exesize = PATH_MAX;
-#endif
- exe = alloca (exesize);
+ struct scratch_buffer exebuf;
+ scratch_buffer_init (&exebuf);
ssize_t nexe;
- while ((nexe = readlinkat (dfd, "exe", exe, exesize)) == exesize)
- extend_alloca (exe, exesize, 2 * exesize);
+ while ((nexe = readlinkat (dfd, "exe",
+ exebuf.data, exebuf.length)) == exebuf.length)
+ {
+ if (!scratch_buffer_grow (&exebuf))
+ {
+ nexe = -1;
+ break;
+ }
+ }
if (nexe == -1)
exe = (char *) "<program name undetermined>";
else
- exe[nexe] = '\0';
+ {
+ exe = exebuf.data;
+ exe[nexe] = '\0';
+ }
/* Stop all threads since otherwise the list of loaded modules might
change while we are reading it. */