svashisht / rpms / bash

Forked from rpms/bash 4 years ago
Clone

Blame SOURCES/bash-4.0-nobits.patch

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