|
|
462fb2 |
diff -up bash-4.2-rc2/config.h.in.interpreter bash-4.2-rc2/config.h.in
|
|
|
462fb2 |
--- bash-4.2-rc2/config.h.in.interpreter 2011-02-09 07:59:21.000000000 +0100
|
|
|
462fb2 |
+++ bash-4.2-rc2/config.h.in 2011-02-09 07:59:21.000000000 +0100
|
|
|
462fb2 |
@@ -706,6 +706,9 @@
|
|
|
462fb2 |
/* Define if you have the pathconf function. */
|
|
|
462fb2 |
#undef HAVE_PATHCONF
|
|
|
462fb2 |
|
|
|
462fb2 |
+/* Define if you have the pread function. */
|
|
|
462fb2 |
+#undef HAVE_PREAD
|
|
|
462fb2 |
+
|
|
|
462fb2 |
/* Define if you have the putenv function. */
|
|
|
462fb2 |
#undef HAVE_PUTENV
|
|
|
462fb2 |
|
|
|
462fb2 |
@@ -898,6 +901,9 @@
|
|
|
462fb2 |
/* Define if you have the <dlfcn.h> header file. */
|
|
|
462fb2 |
#undef HAVE_DLFCN_H
|
|
|
462fb2 |
|
|
|
462fb2 |
+/* Define if you have the <elf.h> header file. */
|
|
|
462fb2 |
+#undef HAVE_ELF_H
|
|
|
462fb2 |
+
|
|
|
462fb2 |
/* Define if you have the <grp.h> header file. */
|
|
|
462fb2 |
#undef HAVE_GRP_H
|
|
|
462fb2 |
|
|
|
462fb2 |
diff -up bash-4.2-rc2/configure.in.interpreter bash-4.2-rc2/configure.in
|
|
|
462fb2 |
--- bash-4.2-rc2/configure.in.interpreter 2011-01-16 21:31:12.000000000 +0100
|
|
|
462fb2 |
+++ bash-4.2-rc2/configure.in 2011-02-09 08:02:27.000000000 +0100
|
|
|
462fb2 |
@@ -659,7 +659,7 @@ BASH_HEADER_INTTYPES
|
|
|
462fb2 |
AC_CHECK_HEADERS(unistd.h stdlib.h stdarg.h varargs.h limits.h string.h \
|
|
|
462fb2 |
memory.h locale.h termcap.h termio.h termios.h dlfcn.h \
|
|
|
462fb2 |
stddef.h stdint.h netdb.h pwd.h grp.h strings.h regex.h \
|
|
|
462fb2 |
- syslog.h ulimit.h)
|
|
|
462fb2 |
+ syslog.h ulimit.h elf.h)
|
|
|
462fb2 |
AC_CHECK_HEADERS(sys/pte.h sys/stream.h sys/select.h sys/file.h \
|
|
|
462fb2 |
sys/resource.h sys/param.h sys/socket.h sys/stat.h \
|
|
|
462fb2 |
sys/time.h sys/times.h sys/types.h sys/wait.h)
|
|
|
462fb2 |
@@ -723,7 +723,7 @@ dnl checks for system calls
|
|
|
462fb2 |
AC_CHECK_FUNCS(dup2 eaccess fcntl getdtablesize getgroups gethostname \
|
|
|
462fb2 |
getpagesize getpeername getrlimit getrusage gettimeofday \
|
|
|
462fb2 |
kill killpg lstat readlink sbrk select setdtablesize \
|
|
|
462fb2 |
- setitimer tcgetpgrp uname ulimit waitpid)
|
|
|
462fb2 |
+ setitimer tcgetpgrp uname ulimit waitpid pread)
|
|
|
462fb2 |
AC_REPLACE_FUNCS(rename)
|
|
|
462fb2 |
|
|
|
462fb2 |
dnl checks for c library functions
|
|
|
462fb2 |
diff -up bash-4.2-rc2/execute_cmd.c.interpreter bash-4.2-rc2/execute_cmd.c
|
|
|
462fb2 |
--- bash-4.2-rc2/execute_cmd.c.interpreter 2011-01-20 04:24:47.000000000 +0100
|
|
|
462fb2 |
+++ bash-4.2-rc2/execute_cmd.c 2011-02-09 07:59:21.000000000 +0100
|
|
|
462fb2 |
@@ -41,6 +41,10 @@
|
|
|
462fb2 |
# include <unistd.h>
|
|
|
462fb2 |
#endif
|
|
|
462fb2 |
|
|
|
462fb2 |
+#ifdef HAVE_ELF_H
|
|
|
462fb2 |
+# include <elf.h>
|
|
|
462fb2 |
+#endif
|
|
|
462fb2 |
+
|
|
|
462fb2 |
#include "posixtime.h"
|
|
|
462fb2 |
|
|
|
462fb2 |
#if defined (HAVE_SYS_RESOURCE_H) && !defined (RLIMTYPE)
|
|
|
462fb2 |
@@ -4975,13 +4979,21 @@ shell_execve (command, args, env)
|
|
|
462fb2 |
{
|
|
|
462fb2 |
/* The file has the execute bits set, but the kernel refuses to
|
|
|
462fb2 |
run it for some reason. See why. */
|
|
|
462fb2 |
+#if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
|
|
|
462fb2 |
+ int fd = open (command, O_RDONLY);
|
|
|
462fb2 |
+
|
|
|
462fb2 |
+ if (fd >= 0)
|
|
|
462fb2 |
+ sample_len = read (fd, sample, sizeof (sample));
|
|
|
462fb2 |
+ else
|
|
|
462fb2 |
+ sample_len = -1;
|
|
|
462fb2 |
+#endif
|
|
|
462fb2 |
#if defined (HAVE_HASH_BANG_EXEC)
|
|
|
462fb2 |
- READ_SAMPLE_BUF (command, sample, sample_len);
|
|
|
462fb2 |
if (sample_len > 2 && sample[0] == '#' && sample[1] == '!')
|
|
|
462fb2 |
{
|
|
|
462fb2 |
char *interp;
|
|
|
462fb2 |
int ilen;
|
|
|
462fb2 |
|
|
|
462fb2 |
+ close (fd);
|
|
|
462fb2 |
interp = getinterp (sample, sample_len, (int *)NULL);
|
|
|
462fb2 |
ilen = strlen (interp);
|
|
|
462fb2 |
errno = i;
|
|
|
462fb2 |
@@ -4997,6 +5009,136 @@ shell_execve (command, args, env)
|
|
|
462fb2 |
return (EX_NOEXEC);
|
|
|
462fb2 |
}
|
|
|
462fb2 |
#endif
|
|
|
462fb2 |
+#if defined (HAVE_ELF_H)
|
|
|
462fb2 |
+ if (i == ENOENT
|
|
|
462fb2 |
+ && sample_len > EI_NIDENT
|
|
|
462fb2 |
+ && memcmp (sample, ELFMAG, SELFMAG) == 0)
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+ off_t offset = -1;
|
|
|
462fb2 |
+
|
|
|
462fb2 |
+ /* It is an ELF file. Now determine whether it is dynamically
|
|
|
462fb2 |
+ linked and if yes, get the offset of the interpreter
|
|
|
462fb2 |
+ string. */
|
|
|
462fb2 |
+ if (sample[EI_CLASS] == ELFCLASS32
|
|
|
462fb2 |
+ && sample_len > sizeof (Elf32_Ehdr))
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+ Elf32_Ehdr ehdr;
|
|
|
462fb2 |
+ Elf32_Phdr *phdr;
|
|
|
462fb2 |
+ int nphdr;
|
|
|
462fb2 |
+
|
|
|
462fb2 |
+ /* We have to copy the data since the sample buffer
|
|
|
462fb2 |
+ might not be aligned correctly to be accessed as
|
|
|
462fb2 |
+ an Elf32_Ehdr struct. */
|
|
|
462fb2 |
+ memcpy (&ehdr, sample, sizeof (Elf32_Ehdr));
|
|
|
462fb2 |
+
|
|
|
462fb2 |
+ nphdr = ehdr.e_phnum;
|
|
|
462fb2 |
+ phdr = (Elf32_Phdr *) malloc (nphdr * ehdr.e_phentsize);
|
|
|
462fb2 |
+ if (phdr != NULL)
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+#ifdef HAVE_PREAD
|
|
|
462fb2 |
+ sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
|
|
|
462fb2 |
+ ehdr.e_phoff);
|
|
|
462fb2 |
+#else
|
|
|
462fb2 |
+ if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
|
|
|
462fb2 |
+ sample_len = read (fd, phdr,
|
|
|
462fb2 |
+ nphdr * ehdr.e_phentsize);
|
|
|
462fb2 |
+ else
|
|
|
462fb2 |
+ sample_len = -1;
|
|
|
462fb2 |
+#endif
|
|
|
462fb2 |
+ if (sample_len == nphdr * ehdr.e_phentsize)
|
|
|
462fb2 |
+ while (nphdr-- > 0)
|
|
|
462fb2 |
+ if (phdr[nphdr].p_type == PT_INTERP)
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+ offset = phdr[nphdr].p_offset;
|
|
|
462fb2 |
+ break;
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+ free (phdr);
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+ else if (sample[EI_CLASS] == ELFCLASS64
|
|
|
462fb2 |
+ && sample_len > sizeof (Elf64_Ehdr))
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+ Elf64_Ehdr ehdr;
|
|
|
462fb2 |
+ Elf64_Phdr *phdr;
|
|
|
462fb2 |
+ int nphdr;
|
|
|
462fb2 |
+
|
|
|
462fb2 |
+ /* We have to copy the data since the sample buffer
|
|
|
462fb2 |
+ might not be aligned correctly to be accessed as
|
|
|
462fb2 |
+ an Elf64_Ehdr struct. */
|
|
|
462fb2 |
+ memcpy (&ehdr, sample, sizeof (Elf64_Ehdr));
|
|
|
462fb2 |
+
|
|
|
462fb2 |
+ nphdr = ehdr.e_phnum;
|
|
|
462fb2 |
+ phdr = (Elf64_Phdr *) malloc (nphdr * ehdr.e_phentsize);
|
|
|
462fb2 |
+ if (phdr != NULL)
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+#ifdef HAVE_PREAD
|
|
|
462fb2 |
+ sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
|
|
|
462fb2 |
+ ehdr.e_phoff);
|
|
|
462fb2 |
+#else
|
|
|
462fb2 |
+ if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
|
|
|
462fb2 |
+ sample_len = read (fd, phdr,
|
|
|
462fb2 |
+ nphdr * ehdr.e_phentsize);
|
|
|
462fb2 |
+ else
|
|
|
462fb2 |
+ sample_len = -1;
|
|
|
462fb2 |
+#endif
|
|
|
462fb2 |
+ if (sample_len == nphdr * ehdr.e_phentsize)
|
|
|
462fb2 |
+ while (nphdr-- > 0)
|
|
|
462fb2 |
+ if (phdr[nphdr].p_type == PT_INTERP)
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+ offset = phdr[nphdr].p_offset;
|
|
|
462fb2 |
+ break;
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+ free (phdr);
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+
|
|
|
462fb2 |
+ if (offset != -1)
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+ size_t maxlen = 0;
|
|
|
462fb2 |
+ size_t actlen = 0;
|
|
|
462fb2 |
+ char *interp = NULL;
|
|
|
462fb2 |
+
|
|
|
462fb2 |
+ do
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+ if (actlen == maxlen)
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+ char *newinterp = realloc (interp, maxlen += 200);
|
|
|
462fb2 |
+ if (newinterp == NULL)
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+ actlen = 0;
|
|
|
462fb2 |
+ break;
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+ interp = newinterp;
|
|
|
462fb2 |
+
|
|
|
462fb2 |
+#ifdef HAVE_PREAD
|
|
|
462fb2 |
+ actlen = pread (fd, interp, maxlen, offset);
|
|
|
462fb2 |
+#else
|
|
|
462fb2 |
+ if (lseek (fd, offset, SEEK_SET) != -1)
|
|
|
462fb2 |
+ actlen = read (fd, interp, maxlen);
|
|
|
462fb2 |
+ else
|
|
|
462fb2 |
+ actlen = -1;
|
|
|
462fb2 |
+#endif
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+ while (actlen > 0 && memchr (interp, '\0', actlen) == NULL);
|
|
|
462fb2 |
+
|
|
|
462fb2 |
+ if (actlen > 0)
|
|
|
462fb2 |
+ {
|
|
|
462fb2 |
+ close (fd);
|
|
|
462fb2 |
+ errno = i;
|
|
|
462fb2 |
+ sys_error ("%s: %s: bad ELF interpreter", command,
|
|
|
462fb2 |
+ interp);
|
|
|
462fb2 |
+ free (interp);
|
|
|
462fb2 |
+ return (EX_NOEXEC);
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+
|
|
|
462fb2 |
+ free (interp);
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+ }
|
|
|
462fb2 |
+#endif
|
|
|
462fb2 |
+#if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
|
|
|
462fb2 |
+ close (fd);
|
|
|
462fb2 |
+#endif
|
|
|
462fb2 |
errno = i;
|
|
|
462fb2 |
file_error (command);
|
|
|
462fb2 |
}
|