|
cvsdist |
4d371b |
--- bash-3.0/config.h.in.interpreter 2004-07-28 09:40:15.259722811 +0100
|
|
cvsdist |
4d371b |
+++ bash-3.0/config.h.in 2004-07-28 09:40:15.429690416 +0100
|
|
cvsdist |
4d371b |
@@ -601,6 +601,9 @@
|
|
cvsdist |
8b5e1e |
/* Define if you have the pathconf function. */
|
|
cvsdist |
8b5e1e |
#undef HAVE_PATHCONF
|
|
cvsdist |
8b5e1e |
|
|
cvsdist |
8b5e1e |
+/* Define if you have the pread function. */
|
|
cvsdist |
8b5e1e |
+#undef HAVE_PREAD
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
/* Define if you have the putenv function. */
|
|
cvsdist |
8b5e1e |
#undef HAVE_PUTENV
|
|
cvsdist |
8b5e1e |
|
|
cvsdist |
4d371b |
@@ -756,6 +759,9 @@
|
|
cvsdist |
8b5e1e |
/* Define if you have the <dlfcn.h> header file. */
|
|
cvsdist |
8b5e1e |
#undef HAVE_DLFCN_H
|
|
cvsdist |
8b5e1e |
|
|
cvsdist |
8b5e1e |
+/* Define if you have the <elf.h> header file. */
|
|
cvsdist |
8b5e1e |
+#undef HAVE_ELF_H
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
/* Define if you have the <grp.h> header file. */
|
|
cvsdist |
8b5e1e |
#undef HAVE_GRP_H
|
|
cvsdist |
8b5e1e |
|
|
cvsdist |
4d371b |
--- bash-3.0/configure.in.interpreter 2004-07-21 21:06:54.000000000 +0100
|
|
cvsdist |
4d371b |
+++ bash-3.0/configure.in 2004-07-28 09:43:21.657196239 +0100
|
|
cvsdist |
4d371b |
@@ -573,7 +573,7 @@
|
|
cvsdist |
8b5e1e |
|
|
cvsdist |
8b5e1e |
AC_CHECK_HEADERS(unistd.h stdlib.h stdarg.h varargs.h limits.h string.h \
|
|
cvsdist |
8b5e1e |
memory.h locale.h termcap.h termio.h termios.h dlfcn.h \
|
|
cvsdist |
4d371b |
- stddef.h stdint.h netdb.h grp.h strings.h regex.h)
|
|
cvsdist |
4d371b |
+ stddef.h stdint.h netdb.h grp.h strings.h regex.h elf.h)
|
|
cvsdist |
8b5e1e |
AC_CHECK_HEADERS(sys/ptem.h sys/pte.h sys/stream.h sys/select.h sys/file.h \
|
|
cvsdist |
4d371b |
sys/resource.h sys/param.h sys/socket.h sys/stat.h \
|
|
cvsdist |
4d371b |
sys/time.h sys/times.h sys/types.h sys/wait.h)
|
|
cvsdist |
4d371b |
@@ -628,7 +628,7 @@
|
|
cvsdist |
4d371b |
AC_CHECK_FUNCS(dup2 select getdtablesize getgroups gethostname \
|
|
cvsdist |
4d371b |
setdtablesize getpagesize killpg lstat getpeername sbrk \
|
|
cvsdist |
4d371b |
getrlimit getrusage gettimeofday waitpid tcgetpgrp \
|
|
cvsdist |
4d371b |
- readlink)
|
|
cvsdist |
4d371b |
+ readlink pread)
|
|
cvsdist |
4d371b |
AC_REPLACE_FUNCS(rename)
|
|
cvsdist |
4d371b |
|
|
cvsdist |
4d371b |
dnl checks for c library functions
|
|
cvsdist |
4d371b |
--- bash-3.0/execute_cmd.c.interpreter 2004-07-28 09:40:15.386698610 +0100
|
|
cvsdist |
4d371b |
+++ bash-3.0/execute_cmd.c 2004-07-28 09:40:15.449686605 +0100
|
|
cvsdist |
8b5e1e |
@@ -40,6 +40,10 @@
|
|
cvsdist |
8b5e1e |
# include <unistd.h>
|
|
cvsdist |
8b5e1e |
#endif
|
|
cvsdist |
8b5e1e |
|
|
cvsdist |
8b5e1e |
+#ifdef HAVE_ELF_H
|
|
cvsdist |
8b5e1e |
+# include <elf.h>
|
|
cvsdist |
8b5e1e |
+#endif
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
#include "posixtime.h"
|
|
cvsdist |
8b5e1e |
|
|
cvsdist |
8b5e1e |
#if defined (HAVE_SYS_RESOURCE_H) && !defined (RLIMTYPE)
|
|
cvsdist |
4d371b |
@@ -3842,12 +3846,20 @@
|
|
cvsdist |
8b5e1e |
{
|
|
cvsdist |
57ff95 |
/* The file has the execute bits set, but the kernel refuses to
|
|
cvsdist |
57ff95 |
run it for some reason. See why. */
|
|
cvsdist |
8b5e1e |
+#if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
|
|
cvsdist |
57ff95 |
+ int fd = open (command, O_RDONLY);
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
57ff95 |
+ if (fd >= 0)
|
|
cvsdist |
57ff95 |
+ sample_len = read (fd, sample, sizeof (sample));
|
|
cvsdist |
57ff95 |
+ else
|
|
cvsdist |
57ff95 |
+ sample_len = -1;
|
|
cvsdist |
8b5e1e |
+#endif
|
|
cvsdist |
8b5e1e |
#if defined (HAVE_HASH_BANG_EXEC)
|
|
cvsdist |
8b5e1e |
- READ_SAMPLE_BUF (command, sample, sample_len);
|
|
cvsdist |
8b5e1e |
if (sample_len > 2 && sample[0] == '#' && sample[1] == '!')
|
|
cvsdist |
8b5e1e |
{
|
|
cvsdist |
8b5e1e |
char *interp;
|
|
cvsdist |
8b5e1e |
|
|
cvsdist |
8b5e1e |
+ close (fd);
|
|
cvsdist |
8b5e1e |
interp = getinterp (sample, sample_len, (int *)NULL);
|
|
cvsdist |
8b5e1e |
errno = i;
|
|
cvsdist |
4d371b |
sys_error (_("%s: %s: bad interpreter"), command, interp ? interp : "");
|
|
cvsdist |
4d371b |
@@ -3855,6 +3867,136 @@
|
|
cvsdist |
8b5e1e |
return (EX_NOEXEC);
|
|
cvsdist |
8b5e1e |
}
|
|
cvsdist |
8b5e1e |
#endif
|
|
cvsdist |
8b5e1e |
+#if defined (HAVE_ELF_H)
|
|
cvsdist |
8b5e1e |
+ if (i == ENOENT
|
|
cvsdist |
8b5e1e |
+ && sample_len > EI_NIDENT
|
|
cvsdist |
8b5e1e |
+ && memcmp (sample, ELFMAG, SELFMAG) == 0)
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+ off_t offset = -1;
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
+ /* It is an ELF file. Now determine whether it is dynamically
|
|
cvsdist |
8b5e1e |
+ linked and if yes, get the offset of the interpreter
|
|
cvsdist |
8b5e1e |
+ string. */
|
|
cvsdist |
8b5e1e |
+ if (sample[EI_CLASS] == ELFCLASS32
|
|
cvsdist |
8b5e1e |
+ && sample_len > sizeof (Elf32_Ehdr))
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+ Elf32_Ehdr ehdr;
|
|
cvsdist |
8b5e1e |
+ Elf32_Phdr *phdr;
|
|
cvsdist |
8b5e1e |
+ int nphdr;
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
+ /* We have to copy the data since the sample buffer
|
|
cvsdist |
8b5e1e |
+ might not be aligned correctly to be accessed as
|
|
cvsdist |
8b5e1e |
+ an Elf32_Ehdr struct. */
|
|
cvsdist |
8b5e1e |
+ memcpy (&ehdr, sample, sizeof (Elf32_Ehdr));
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
+ nphdr = ehdr.e_phnum;
|
|
cvsdist |
8b5e1e |
+ phdr = (Elf32_Phdr *) malloc (nphdr * ehdr.e_phentsize);
|
|
cvsdist |
8b5e1e |
+ if (phdr != NULL)
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+#ifdef HAVE_PREAD
|
|
cvsdist |
8b5e1e |
+ sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
|
|
cvsdist |
8b5e1e |
+ ehdr.e_phoff);
|
|
cvsdist |
8b5e1e |
+#else
|
|
cvsdist |
8b5e1e |
+ if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
|
|
cvsdist |
8b5e1e |
+ sample_len = read (fd, phdr,
|
|
cvsdist |
8b5e1e |
+ nphdr * ehdr.e_phentsize);
|
|
cvsdist |
8b5e1e |
+ else
|
|
cvsdist |
8b5e1e |
+ sample_len = -1;
|
|
cvsdist |
8b5e1e |
+#endif
|
|
cvsdist |
8b5e1e |
+ if (sample_len == nphdr * ehdr.e_phentsize)
|
|
cvsdist |
8b5e1e |
+ while (nphdr-- > 0)
|
|
cvsdist |
8b5e1e |
+ if (phdr[nphdr].p_type == PT_INTERP)
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+ offset = phdr[nphdr].p_offset;
|
|
cvsdist |
8b5e1e |
+ break;
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+ free (phdr);
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+ else if (sample[EI_CLASS] == ELFCLASS64
|
|
cvsdist |
8b5e1e |
+ && sample_len > sizeof (Elf64_Ehdr))
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+ Elf64_Ehdr ehdr;
|
|
cvsdist |
8b5e1e |
+ Elf64_Phdr *phdr;
|
|
cvsdist |
8b5e1e |
+ int nphdr;
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
+ /* We have to copy the data since the sample buffer
|
|
cvsdist |
8b5e1e |
+ might not be aligned correctly to be accessed as
|
|
cvsdist |
8b5e1e |
+ an Elf64_Ehdr struct. */
|
|
cvsdist |
8b5e1e |
+ memcpy (&ehdr, sample, sizeof (Elf64_Ehdr));
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
+ nphdr = ehdr.e_phnum;
|
|
cvsdist |
8b5e1e |
+ phdr = (Elf64_Phdr *) malloc (nphdr * ehdr.e_phentsize);
|
|
cvsdist |
8b5e1e |
+ if (phdr != NULL)
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+#ifdef HAVE_PREAD
|
|
cvsdist |
8b5e1e |
+ sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
|
|
cvsdist |
8b5e1e |
+ ehdr.e_phoff);
|
|
cvsdist |
8b5e1e |
+#else
|
|
cvsdist |
8b5e1e |
+ if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
|
|
cvsdist |
8b5e1e |
+ sample_len = read (fd, phdr,
|
|
cvsdist |
8b5e1e |
+ nphdr * ehdr.e_phentsize);
|
|
cvsdist |
8b5e1e |
+ else
|
|
cvsdist |
8b5e1e |
+ sample_len = -1;
|
|
cvsdist |
8b5e1e |
+#endif
|
|
cvsdist |
8b5e1e |
+ if (sample_len == nphdr * ehdr.e_phentsize)
|
|
cvsdist |
8b5e1e |
+ while (nphdr-- > 0)
|
|
cvsdist |
8b5e1e |
+ if (phdr[nphdr].p_type == PT_INTERP)
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+ offset = phdr[nphdr].p_offset;
|
|
cvsdist |
8b5e1e |
+ break;
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+ free (phdr);
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
+ if (offset != -1)
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+ size_t maxlen = 0;
|
|
cvsdist |
8b5e1e |
+ size_t actlen = 0;
|
|
cvsdist |
8b5e1e |
+ char *interp = NULL;
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
+ do
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+ if (actlen == maxlen)
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+ char *newinterp = realloc (interp, maxlen += 200);
|
|
cvsdist |
8b5e1e |
+ if (newinterp == NULL)
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+ actlen = 0;
|
|
cvsdist |
8b5e1e |
+ break;
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+ interp = newinterp;
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
+#ifdef HAVE_PREAD
|
|
cvsdist |
8b5e1e |
+ actlen = pread (fd, interp, maxlen, offset);
|
|
cvsdist |
8b5e1e |
+#else
|
|
cvsdist |
8b5e1e |
+ if (lseek (fd, offset, SEEK_SET) != -1)
|
|
cvsdist |
8b5e1e |
+ actlen = read (fd, interp, maxlen);
|
|
cvsdist |
8b5e1e |
+ else
|
|
cvsdist |
8b5e1e |
+ actlen = -1;
|
|
cvsdist |
8b5e1e |
+#endif
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+ while (actlen > 0 && memchr (interp, '\0', actlen) == NULL);
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
+ if (actlen > 0)
|
|
cvsdist |
8b5e1e |
+ {
|
|
cvsdist |
8b5e1e |
+ close (fd);
|
|
cvsdist |
8b5e1e |
+ errno = i;
|
|
cvsdist |
8b5e1e |
+ sys_error ("%s: %s: bad ELF interpreter", command,
|
|
cvsdist |
8b5e1e |
+ interp);
|
|
cvsdist |
8b5e1e |
+ free (interp);
|
|
cvsdist |
8b5e1e |
+ return (EX_NOEXEC);
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+
|
|
cvsdist |
8b5e1e |
+ free (interp);
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+ }
|
|
cvsdist |
8b5e1e |
+#endif
|
|
cvsdist |
8b5e1e |
+#if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
|
|
cvsdist |
8b5e1e |
+ close (fd);
|
|
cvsdist |
8b5e1e |
+#endif
|
|
cvsdist |
8b5e1e |
errno = i;
|
|
cvsdist |
8b5e1e |
file_error (command);
|
|
cvsdist |
8b5e1e |
}
|