summaryrefslogtreecommitdiff
path: root/elf/pldd.c
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/pldd.c
parentda0cf658c6758d2e6d1b1b99312f66150ccc7a43 (diff)
downloadglibc-7b8399f479fb9ebaf816a49246ea5c6354a0769e.tar.gz
pldd: Use struct scratch_buffer instead of extend_alloca
Diffstat (limited to 'elf/pldd.c')
-rw-r--r--elf/pldd.c24
1 files changed, 16 insertions, 8 deletions
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. */