bash/bash-2.05a-interpreter.patch
cvsdist 57ff95e718 auto-import changelog data from bash-2.05b-2.src.rpm
Tue Jul 23 2002 Phil Knirsch <pknirsch@redhat.com> 2.05b-2
- Added symlink for sh.1 in man1 section so that man sh works (#44039).
Mon Jul 22 2002 Phil Knirsch <pknirsch@redhat.com> 2.05b-1
- Update to 2.05b
Wed Jul 10 2002 Phil Knirsch <pknirsch@redhat.com> 2.05a-16
- Fixed readline utf8 problem (#68313).
Fri Jun 21 2002 Tim Powers <timp@redhat.com> 2.05a-15
- automated rebuild
Thu May 23 2002 Tim Powers <timp@redhat.com> 2.05a-14
- automated rebuild
2004-09-09 03:26:36 +00:00

215 lines
5.9 KiB
Diff

--- bash-2.05b/config.h.in.interpreter 2002-07-22 12:30:53.000000000 +0200
+++ bash-2.05b/config.h.in 2002-07-22 12:30:54.000000000 +0200
@@ -579,6 +579,9 @@
/* Define if you have the pathconf function. */
#undef HAVE_PATHCONF
+/* Define if you have the pread function. */
+#undef HAVE_PREAD
+
/* Define if you have the putenv function. */
#undef HAVE_PUTENV
@@ -722,6 +725,9 @@
/* Define if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
+/* Define if you have the <elf.h> header file. */
+#undef HAVE_ELF_H
+
/* Define if you have the <grp.h> header file. */
#undef HAVE_GRP_H
--- bash-2.05b/configure.in.interpreter 2002-07-16 15:31:25.000000000 +0200
+++ bash-2.05b/configure.in 2002-07-22 12:30:54.000000000 +0200
@@ -525,7 +525,7 @@
AC_CHECK_HEADERS(unistd.h stdlib.h stdarg.h varargs.h limits.h string.h \
memory.h locale.h termcap.h termio.h termios.h dlfcn.h \
- stddef.h stdint.h netdb.h grp.h strings.h)
+ stddef.h stdint.h netdb.h grp.h strings.h elf.h)
AC_CHECK_HEADERS(sys/ptem.h sys/pte.h sys/stream.h sys/select.h sys/file.h \
sys/resource.h sys/param.h sys/socket.h \
sys/time.h sys/times.h sys/wait.h)
@@ -588,7 +588,7 @@
setlinebuf setvbuf setlocale strchr tcgetattr uname \
ulimit tzset siginterrupt memmove ttyname times \
getaddrinfo gethostbyname getservbyname getservent inet_aton \
- vsnprintf snprintf vasprintf asprintf fnmatch)
+ vsnprintf snprintf vasprintf asprintf fnmatch pread)
AC_CHECK_FUNCS(isascii isblank isgraph isprint isspace isxdigit)
AC_REPLACE_FUNCS(getcwd strcasecmp strerror strftime strpbrk memset)
AC_REPLACE_FUNCS(strtod strtol strtoul strtoll strtoull strtoimax strtoumax)
--- bash-2.05b/execute_cmd.c.interpreter 2002-07-22 12:30:54.000000000 +0200
+++ bash-2.05b/execute_cmd.c 2002-07-22 12:40:08.000000000 +0200
@@ -40,6 +40,10 @@
# include <unistd.h>
#endif
+#ifdef HAVE_ELF_H
+# include <elf.h>
+#endif
+
#include "posixtime.h"
#if defined (HAVE_SYS_RESOURCE_H) && !defined (RLIMTYPE)
@@ -3496,12 +3500,20 @@
{
/* The file has the execute bits set, but the kernel refuses to
run it for some reason. See why. */
+#if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
+ int fd = open (command, O_RDONLY);
+
+ if (fd >= 0)
+ sample_len = read (fd, sample, sizeof (sample));
+ else
+ sample_len = -1;
+#endif
#if defined (HAVE_HASH_BANG_EXEC)
- READ_SAMPLE_BUF (command, sample, sample_len);
if (sample_len > 2 && sample[0] == '#' && sample[1] == '!')
{
char *interp;
+ close (fd);
interp = getinterp (sample, sample_len, (int *)NULL);
errno = i;
sys_error ("%s: %s: bad interpreter", command, interp ? interp : "");
@@ -3509,6 +3521,136 @@
return (EX_NOEXEC);
}
#endif
+#if defined (HAVE_ELF_H)
+ if (i == ENOENT
+ && sample_len > EI_NIDENT
+ && memcmp (sample, ELFMAG, SELFMAG) == 0)
+ {
+ off_t offset = -1;
+
+ /* It is an ELF file. Now determine whether it is dynamically
+ linked and if yes, get the offset of the interpreter
+ string. */
+ if (sample[EI_CLASS] == ELFCLASS32
+ && sample_len > sizeof (Elf32_Ehdr))
+ {
+ Elf32_Ehdr ehdr;
+ Elf32_Phdr *phdr;
+ int nphdr;
+
+ /* We have to copy the data since the sample buffer
+ might not be aligned correctly to be accessed as
+ an Elf32_Ehdr struct. */
+ memcpy (&ehdr, sample, sizeof (Elf32_Ehdr));
+
+ nphdr = ehdr.e_phnum;
+ phdr = (Elf32_Phdr *) malloc (nphdr * ehdr.e_phentsize);
+ if (phdr != NULL)
+ {
+#ifdef HAVE_PREAD
+ sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
+ ehdr.e_phoff);
+#else
+ if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
+ sample_len = read (fd, phdr,
+ nphdr * ehdr.e_phentsize);
+ else
+ sample_len = -1;
+#endif
+ if (sample_len == nphdr * ehdr.e_phentsize)
+ while (nphdr-- > 0)
+ if (phdr[nphdr].p_type == PT_INTERP)
+ {
+ offset = phdr[nphdr].p_offset;
+ break;
+ }
+ free (phdr);
+ }
+ }
+ else if (sample[EI_CLASS] == ELFCLASS64
+ && sample_len > sizeof (Elf64_Ehdr))
+ {
+ Elf64_Ehdr ehdr;
+ Elf64_Phdr *phdr;
+ int nphdr;
+
+ /* We have to copy the data since the sample buffer
+ might not be aligned correctly to be accessed as
+ an Elf64_Ehdr struct. */
+ memcpy (&ehdr, sample, sizeof (Elf64_Ehdr));
+
+ nphdr = ehdr.e_phnum;
+ phdr = (Elf64_Phdr *) malloc (nphdr * ehdr.e_phentsize);
+ if (phdr != NULL)
+ {
+#ifdef HAVE_PREAD
+ sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
+ ehdr.e_phoff);
+#else
+ if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
+ sample_len = read (fd, phdr,
+ nphdr * ehdr.e_phentsize);
+ else
+ sample_len = -1;
+#endif
+ if (sample_len == nphdr * ehdr.e_phentsize)
+ while (nphdr-- > 0)
+ if (phdr[nphdr].p_type == PT_INTERP)
+ {
+ offset = phdr[nphdr].p_offset;
+ break;
+ }
+ free (phdr);
+ }
+ }
+
+ if (offset != -1)
+ {
+ size_t maxlen = 0;
+ size_t actlen = 0;
+ char *interp = NULL;
+
+ do
+ {
+ if (actlen == maxlen)
+ {
+ char *newinterp = realloc (interp, maxlen += 200);
+ if (newinterp == NULL)
+ {
+ actlen = 0;
+ break;
+ }
+ interp = newinterp;
+
+#ifdef HAVE_PREAD
+ actlen = pread (fd, interp, maxlen, offset);
+#else
+ if (lseek (fd, offset, SEEK_SET) != -1)
+ actlen = read (fd, interp, maxlen);
+ else
+ actlen = -1;
+#endif
+ }
+ }
+ while (actlen > 0 && memchr (interp, '\0', actlen) == NULL);
+
+ if (actlen > 0)
+ {
+ close (fd);
+ errno = i;
+ sys_error ("%s: %s: bad ELF interpreter", command,
+ interp);
+ free (interp);
+ return (EX_NOEXEC);
+ }
+
+ free (interp);
+ }
+ }
+#endif
+#if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
+ close (fd);
+#endif
errno = i;
file_error (command);
}