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