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