462fb2
diff -up bash-4.0/execute_cmd.c.nobits bash-4.0/execute_cmd.c
462fb2
--- bash-4.0/execute_cmd.c.nobits	2009-08-11 11:53:38.000000000 +0200
462fb2
+++ bash-4.0/execute_cmd.c	2009-08-14 16:18:18.000000000 +0200
462fb2
@@ -4747,6 +4747,7 @@ shell_execve (command, args, env)
462fb2
 	      && memcmp (sample, ELFMAG, SELFMAG) == 0)
462fb2
 	    {
462fb2
 	      off_t offset = -1;
462fb2
+              int dynamic_nobits = 0;
462fb2
 
462fb2
 	      /* It is an ELF file.  Now determine whether it is dynamically
462fb2
 		 linked and if yes, get the offset of the interpreter
462fb2
@@ -4756,13 +4757,61 @@ shell_execve (command, args, env)
462fb2
 		{
462fb2
 		  Elf32_Ehdr ehdr;
462fb2
 		  Elf32_Phdr *phdr;
462fb2
-		  int nphdr;
462fb2
+                  Elf32_Shdr *shdr;
462fb2
+		  int nphdr, nshdr;
462fb2
 
462fb2
 		  /* We have to copy the data since the sample buffer
462fb2
 		     might not be aligned correctly to be accessed as
462fb2
 		     an Elf32_Ehdr struct.  */
462fb2
 		  memcpy (&ehdr, sample, sizeof (Elf32_Ehdr));
462fb2
 
462fb2
+		  nshdr = ehdr.e_shnum;
462fb2
+		  shdr = (Elf32_Shdr *) malloc (nshdr * ehdr.e_shentsize);
462fb2
+                  
462fb2
+		  if (shdr != NULL)
462fb2
+		    {
462fb2
+#ifdef HAVE_PREAD
462fb2
+		      sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize,
462fb2
+					  ehdr.e_shoff);
462fb2
+#else
462fb2
+		      if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1)
462fb2
+			sample_len = read (fd, shdr,
462fb2
+					   nshdr * ehdr.e_shentsize);
462fb2
+		      else
462fb2
+			sample_len = -1;
462fb2
+#endif
462fb2
+		      if (sample_len == nshdr * ehdr.e_shentsize)
462fb2
+                        {
462fb2
+                          char *strings = (char *) malloc (shdr[ehdr.e_shstrndx].sh_size);
462fb2
+                          if (strings != NULL)
462fb2
+                            {
462fb2
+#ifdef HAVE_PREAD
462fb2
+		              sample_len = pread (fd, strings,
462fb2
+                                             shdr[ehdr.e_shstrndx].sh_size,
462fb2
+					     shdr[ehdr.e_shstrndx].sh_offset);
462fb2
+#else
462fb2
+		              if (lseek (fd, shdr[ehdr.e_shstrndx].sh_offset,
462fb2
+                                         SEEK_SET) != -1)
462fb2
+			        sample_len = read (fd, strings,
462fb2
+			  		       shdr[ehdr.e_shstrndx].sh_size);
462fb2
+		              else
462fb2
+			        sample_len = -1;
462fb2
+#endif
462fb2
+                              if (sample_len == shdr[ehdr.e_shstrndx].sh_size)
462fb2
+			        while (nshdr-- > 0)
462fb2
+                                  if (strcmp (strings + shdr[nshdr].sh_name,
462fb2
+                                              ".interp") == 0 &&
462fb2
+                                      shdr[nshdr].sh_type == SHT_NOBITS)
462fb2
+                                    {
462fb2
+                                      dynamic_nobits++;
462fb2
+                                      break;
462fb2
+                                    }
462fb2
+                              free (strings);
462fb2
+                            }
462fb2
+                        }
462fb2
+		      free (shdr);
462fb2
+		    }
462fb2
+
462fb2
 		  nphdr = ehdr.e_phnum;
462fb2
 		  phdr = (Elf32_Phdr *) malloc (nphdr * ehdr.e_phentsize);
462fb2
 		  if (phdr != NULL)
462fb2
@@ -4792,13 +4841,60 @@ shell_execve (command, args, env)
462fb2
 		{
462fb2
 		  Elf64_Ehdr ehdr;
462fb2
 		  Elf64_Phdr *phdr;
462fb2
-		  int nphdr;
462fb2
+                  Elf64_Shdr *shdr;
462fb2
+		  int nphdr, nshdr;
462fb2
 
462fb2
 		  /* We have to copy the data since the sample buffer
462fb2
 		     might not be aligned correctly to be accessed as
462fb2
 		     an Elf64_Ehdr struct.  */
462fb2
 		  memcpy (&ehdr, sample, sizeof (Elf64_Ehdr));
462fb2
 
462fb2
+		  nshdr = ehdr.e_shnum;
462fb2
+		  shdr = (Elf64_Shdr *) malloc (nshdr * ehdr.e_shentsize);
462fb2
+		  if (shdr != NULL)
462fb2
+		    {
462fb2
+#ifdef HAVE_PREAD
462fb2
+		      sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize,
462fb2
+					  ehdr.e_shoff);
462fb2
+#else
462fb2
+		      if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1)
462fb2
+			sample_len = read (fd, shdr,
462fb2
+					   nshdr * ehdr.e_shentsize);
462fb2
+		      else
462fb2
+			sample_len = -1;
462fb2
+#endif
462fb2
+		      if (sample_len == nshdr * ehdr.e_shentsize)
462fb2
+                        {
462fb2
+                          char *strings = (char *) malloc (shdr[ehdr.e_shstrndx].sh_size);
462fb2
+                          if (strings != NULL)
462fb2
+                            {
462fb2
+#ifdef HAVE_PREAD
462fb2
+		              sample_len = pread (fd, strings,
462fb2
+                                             shdr[ehdr.e_shstrndx].sh_size,
462fb2
+					     shdr[ehdr.e_shstrndx].sh_offset);
462fb2
+#else
462fb2
+		              if (lseek (fd, shdr[ehdr.e_shstrndx].sh_offset,
462fb2
+                                         SEEK_SET) != -1)
462fb2
+			        sample_len = read (fd, strings,
462fb2
+			  		       shdr[ehdr.e_shstrndx].sh_size);
462fb2
+		              else
462fb2
+			        sample_len = -1;
462fb2
+#endif
462fb2
+                              if (sample_len == shdr[ehdr.e_shstrndx].sh_size)
462fb2
+			        while (nshdr-- > 0)
462fb2
+                                  if (strcmp (strings + shdr[nshdr].sh_name,
462fb2
+                                              ".interp") == 0 &&
462fb2
+                                      shdr[nshdr].sh_type == SHT_NOBITS)
462fb2
+                                    {
462fb2
+                                      dynamic_nobits++;
462fb2
+                                      break;
462fb2
+                                    }
462fb2
+                              free (strings);
462fb2
+                            }
462fb2
+                        }
462fb2
+		      free (shdr);
462fb2
+		    }
462fb2
+
462fb2
 		  nphdr = ehdr.e_phnum;
462fb2
 		  phdr = (Elf64_Phdr *) malloc (nphdr * ehdr.e_phentsize);
462fb2
 		  if (phdr != NULL)
462fb2
@@ -4858,8 +4954,15 @@ shell_execve (command, args, env)
462fb2
 		    {
462fb2
 		      close (fd);
462fb2
 		      errno = i;
462fb2
-		      sys_error ("%s: %s: bad ELF interpreter", command,
462fb2
-				 interp);
462fb2
+                      if (dynamic_nobits > 0)
462fb2
+                        {
462fb2
+                          sys_error ("%s: bad ELF interpreter", command);
462fb2
+                        }
462fb2
+                      else
462fb2
+                        {
462fb2
+		          sys_error ("%s: %s: bad ELF interpreter", command,
462fb2
+				     interp);
462fb2
+                        }
462fb2
 		      free (interp);
462fb2
 		      return (EX_NOEXEC);
462fb2
 		    }