]> git.ipfire.org Git - people/stevee/ipfire-3.x.git/blob - bash/patches/bash-4.0-nobits.patch
readline: Update to 7.0
[people/stevee/ipfire-3.x.git] / bash / patches / bash-4.0-nobits.patch
1 diff -up bash-4.0/execute_cmd.c.nobits bash-4.0/execute_cmd.c
2 --- bash-4.0/execute_cmd.c.nobits 2009-08-11 11:53:38.000000000 +0200
3 +++ bash-4.0/execute_cmd.c 2009-08-14 16:18:18.000000000 +0200
4 @@ -4747,6 +4747,7 @@ shell_execve (command, args, env)
5 && memcmp (sample, ELFMAG, SELFMAG) == 0)
6 {
7 off_t offset = -1;
8 + int dynamic_nobits = 0;
9
10 /* It is an ELF file. Now determine whether it is dynamically
11 linked and if yes, get the offset of the interpreter
12 @@ -4756,13 +4757,61 @@ shell_execve (command, args, env)
13 {
14 Elf32_Ehdr ehdr;
15 Elf32_Phdr *phdr;
16 - int nphdr;
17 + Elf32_Shdr *shdr;
18 + int nphdr, nshdr;
19
20 /* We have to copy the data since the sample buffer
21 might not be aligned correctly to be accessed as
22 an Elf32_Ehdr struct. */
23 memcpy (&ehdr, sample, sizeof (Elf32_Ehdr));
24
25 + nshdr = ehdr.e_shnum;
26 + shdr = (Elf32_Shdr *) malloc (nshdr * ehdr.e_shentsize);
27 +
28 + if (shdr != NULL)
29 + {
30 +#ifdef HAVE_PREAD
31 + sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize,
32 + ehdr.e_shoff);
33 +#else
34 + if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1)
35 + sample_len = read (fd, shdr,
36 + nshdr * ehdr.e_shentsize);
37 + else
38 + sample_len = -1;
39 +#endif
40 + if (sample_len == nshdr * ehdr.e_shentsize)
41 + {
42 + char *strings = (char *) malloc (shdr[ehdr.e_shstrndx].sh_size);
43 + if (strings != NULL)
44 + {
45 +#ifdef HAVE_PREAD
46 + sample_len = pread (fd, strings,
47 + shdr[ehdr.e_shstrndx].sh_size,
48 + shdr[ehdr.e_shstrndx].sh_offset);
49 +#else
50 + if (lseek (fd, shdr[ehdr.e_shstrndx].sh_offset,
51 + SEEK_SET) != -1)
52 + sample_len = read (fd, strings,
53 + shdr[ehdr.e_shstrndx].sh_size);
54 + else
55 + sample_len = -1;
56 +#endif
57 + if (sample_len == shdr[ehdr.e_shstrndx].sh_size)
58 + while (nshdr-- > 0)
59 + if (strcmp (strings + shdr[nshdr].sh_name,
60 + ".interp") == 0 &&
61 + shdr[nshdr].sh_type == SHT_NOBITS)
62 + {
63 + dynamic_nobits++;
64 + break;
65 + }
66 + free (strings);
67 + }
68 + }
69 + free (shdr);
70 + }
71 +
72 nphdr = ehdr.e_phnum;
73 phdr = (Elf32_Phdr *) malloc (nphdr * ehdr.e_phentsize);
74 if (phdr != NULL)
75 @@ -4792,13 +4841,60 @@ shell_execve (command, args, env)
76 {
77 Elf64_Ehdr ehdr;
78 Elf64_Phdr *phdr;
79 - int nphdr;
80 + Elf64_Shdr *shdr;
81 + int nphdr, nshdr;
82
83 /* We have to copy the data since the sample buffer
84 might not be aligned correctly to be accessed as
85 an Elf64_Ehdr struct. */
86 memcpy (&ehdr, sample, sizeof (Elf64_Ehdr));
87
88 + nshdr = ehdr.e_shnum;
89 + shdr = (Elf64_Shdr *) malloc (nshdr * ehdr.e_shentsize);
90 + if (shdr != NULL)
91 + {
92 +#ifdef HAVE_PREAD
93 + sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize,
94 + ehdr.e_shoff);
95 +#else
96 + if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1)
97 + sample_len = read (fd, shdr,
98 + nshdr * ehdr.e_shentsize);
99 + else
100 + sample_len = -1;
101 +#endif
102 + if (sample_len == nshdr * ehdr.e_shentsize)
103 + {
104 + char *strings = (char *) malloc (shdr[ehdr.e_shstrndx].sh_size);
105 + if (strings != NULL)
106 + {
107 +#ifdef HAVE_PREAD
108 + sample_len = pread (fd, strings,
109 + shdr[ehdr.e_shstrndx].sh_size,
110 + shdr[ehdr.e_shstrndx].sh_offset);
111 +#else
112 + if (lseek (fd, shdr[ehdr.e_shstrndx].sh_offset,
113 + SEEK_SET) != -1)
114 + sample_len = read (fd, strings,
115 + shdr[ehdr.e_shstrndx].sh_size);
116 + else
117 + sample_len = -1;
118 +#endif
119 + if (sample_len == shdr[ehdr.e_shstrndx].sh_size)
120 + while (nshdr-- > 0)
121 + if (strcmp (strings + shdr[nshdr].sh_name,
122 + ".interp") == 0 &&
123 + shdr[nshdr].sh_type == SHT_NOBITS)
124 + {
125 + dynamic_nobits++;
126 + break;
127 + }
128 + free (strings);
129 + }
130 + }
131 + free (shdr);
132 + }
133 +
134 nphdr = ehdr.e_phnum;
135 phdr = (Elf64_Phdr *) malloc (nphdr * ehdr.e_phentsize);
136 if (phdr != NULL)
137 @@ -4858,8 +4954,15 @@ shell_execve (command, args, env)
138 {
139 close (fd);
140 errno = i;
141 - sys_error ("%s: %s: bad ELF interpreter", command,
142 - interp);
143 + if (dynamic_nobits > 0)
144 + {
145 + sys_error ("%s: bad ELF interpreter", command);
146 + }
147 + else
148 + {
149 + sys_error ("%s: %s: bad ELF interpreter", command,
150 + interp);
151 + }
152 free (interp);
153 return (EX_NOEXEC);
154 }