rcolebaugh / rpms / bash

Forked from rpms/bash 2 years ago
Clone

Blame SOURCES/bash-4.0-nobits.patch

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