1 diff -up bash-4.2-rc2/config.h.in.interpreter bash-4.2-rc2/config.h.in
2 --- bash-4.2-rc2/config.h.in.interpreter 2011-02-09 07:59:21.000000000 +0100
3 +++ bash-4.2-rc2/config.h.in 2011-02-09 07:59:21.000000000 +0100
5 /* Define if you have the pathconf function. */
8 +/* Define if you have the pread function. */
11 /* Define if you have the putenv function. */
15 /* Define if you have the <dlfcn.h> header file. */
18 +/* Define if you have the <elf.h> header file. */
21 /* Define if you have the <grp.h> header file. */
24 diff -up bash-4.2-rc2/configure.in.interpreter bash-4.2-rc2/configure.in
25 --- bash-4.2-rc2/configure.in.interpreter 2011-01-16 21:31:12.000000000 +0100
26 +++ bash-4.2-rc2/configure.ac 2011-02-09 08:02:27.000000000 +0100
27 @@ -659,7 +659,7 @@ BASH_HEADER_INTTYPES
28 AC_CHECK_HEADERS(unistd.h stdlib.h stdarg.h varargs.h limits.h string.h \
29 memory.h locale.h termcap.h termio.h termios.h dlfcn.h \
30 stdbool.h stddef.h stdint.h netdb.h pwd.h grp.h strings.h \
31 - regex.h syslog.h ulimit.h)
32 + regex.h syslog.h ulimit.h elf.h)
33 AC_CHECK_HEADERS(sys/pte.h sys/stream.h sys/select.h sys/file.h \
34 sys/resource.h sys/param.h sys/socket.h sys/stat.h \
35 sys/time.h sys/times.h sys/types.h sys/wait.h)
36 @@ -723,7 +723,7 @@ dnl checks for system calls
37 AC_CHECK_FUNCS(dup2 eaccess fcntl getdtablesize getgroups gethostname \
38 getpagesize getpeername getrlimit getrusage gettimeofday \
39 kill killpg lstat readlink sbrk select setdtablesize \
40 - setitimer tcgetpgrp uname ulimit waitpid)
41 + setitimer tcgetpgrp uname ulimit waitpid pread)
42 AC_REPLACE_FUNCS(rename)
44 dnl checks for c library functions
45 diff -up bash-4.2-rc2/execute_cmd.c.interpreter bash-4.2-rc2/execute_cmd.c
46 --- bash-4.2-rc2/execute_cmd.c.interpreter 2011-01-20 04:24:47.000000000 +0100
47 +++ bash-4.2-rc2/execute_cmd.c 2011-02-09 07:59:21.000000000 +0100
56 #include "posixtime.h"
58 #if defined (HAVE_SYS_RESOURCE_H) && !defined (RLIMTYPE)
59 @@ -4975,14 +4979,22 @@ shell_execve (command, args, env)
61 /* The file has the execute bits set, but the kernel refuses to
62 run it for some reason. See why. */
63 +#if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
64 + int fd = open (command, O_RDONLY);
67 + sample_len = read (fd, sample, sizeof (sample));
71 #if defined (HAVE_HASH_BANG_EXEC)
72 - READ_SAMPLE_BUF (command, sample, sample_len);
73 sample[sample_len - 1] = '\0';
74 if (sample_len > 2 && sample[0] == '#' && sample[1] == '!')
80 interp = getinterp (sample, sample_len, (int *)NULL);
81 ilen = strlen (interp);
83 @@ -4997,6 +5009,136 @@ shell_execve (command, args, env)
87 +#if defined (HAVE_ELF_H)
89 + && sample_len > EI_NIDENT
90 + && memcmp (sample, ELFMAG, SELFMAG) == 0)
94 + /* It is an ELF file. Now determine whether it is dynamically
95 + linked and if yes, get the offset of the interpreter
97 + if (sample[EI_CLASS] == ELFCLASS32
98 + && sample_len > sizeof (Elf32_Ehdr))
104 + /* We have to copy the data since the sample buffer
105 + might not be aligned correctly to be accessed as
106 + an Elf32_Ehdr struct. */
107 + memcpy (&ehdr, sample, sizeof (Elf32_Ehdr));
109 + nphdr = ehdr.e_phnum;
110 + phdr = (Elf32_Phdr *) malloc (nphdr * ehdr.e_phentsize);
114 + sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
117 + if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
118 + sample_len = read (fd, phdr,
119 + nphdr * ehdr.e_phentsize);
123 + if (sample_len == nphdr * ehdr.e_phentsize)
124 + while (nphdr-- > 0)
125 + if (phdr[nphdr].p_type == PT_INTERP)
127 + offset = phdr[nphdr].p_offset;
133 + else if (sample[EI_CLASS] == ELFCLASS64
134 + && sample_len > sizeof (Elf64_Ehdr))
140 + /* We have to copy the data since the sample buffer
141 + might not be aligned correctly to be accessed as
142 + an Elf64_Ehdr struct. */
143 + memcpy (&ehdr, sample, sizeof (Elf64_Ehdr));
145 + nphdr = ehdr.e_phnum;
146 + phdr = (Elf64_Phdr *) malloc (nphdr * ehdr.e_phentsize);
150 + sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
153 + if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
154 + sample_len = read (fd, phdr,
155 + nphdr * ehdr.e_phentsize);
159 + if (sample_len == nphdr * ehdr.e_phentsize)
160 + while (nphdr-- > 0)
161 + if (phdr[nphdr].p_type == PT_INTERP)
163 + offset = phdr[nphdr].p_offset;
174 + char *interp = NULL;
178 + if (actlen == maxlen)
180 + char *newinterp = realloc (interp, maxlen += 200);
181 + if (newinterp == NULL)
186 + interp = newinterp;
189 + actlen = pread (fd, interp, maxlen, offset);
191 + if (lseek (fd, offset, SEEK_SET) != -1)
192 + actlen = read (fd, interp, maxlen);
198 + while (actlen > 0 && memchr (interp, '\0', actlen) == NULL);
204 + sys_error ("%s: %s: bad ELF interpreter", command,
207 + return (EX_NOEXEC);
214 +#if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
218 file_error (command);