462fb2
diff -up bash-4.2/execute_cmd.c.coverity bash-4.2/execute_cmd.c
462fb2
--- bash-4.2/execute_cmd.c.coverity	2011-02-24 13:04:35.000000000 +0100
462fb2
+++ bash-4.2/execute_cmd.c	2011-02-24 13:49:13.000000000 +0100
462fb2
@@ -5036,7 +5036,7 @@ shell_execve (command, args, env)
462fb2
 		  Elf32_Ehdr ehdr;
462fb2
 		  Elf32_Phdr *phdr;
462fb2
                   Elf32_Shdr *shdr;
462fb2
-		  int nphdr, nshdr;
462fb2
+		  Elf32_Half 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
@@ -5044,12 +5044,12 @@ shell_execve (command, args, env)
462fb2
 		  memcpy (&ehdr, sample, sizeof (Elf32_Ehdr));
462fb2
 
462fb2
 		  nshdr = ehdr.e_shnum;
462fb2
-		  shdr = (Elf32_Shdr *) malloc (nshdr * ehdr.e_shentsize);
462fb2
+		  shdr = (Elf32_Shdr *) malloc ((size_t)nshdr * (size_t)ehdr.e_shentsize);
462fb2
                   
462fb2
 		  if (shdr != NULL)
462fb2
 		    {
462fb2
 #ifdef HAVE_PREAD
462fb2
-		      sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize,
462fb2
+		      sample_len = pread (fd, shdr, (size_t)nshdr * (size_t)ehdr.e_shentsize,
462fb2
 					  ehdr.e_shoff);
462fb2
 #else
462fb2
 		      if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1)
462fb2
@@ -5091,11 +5091,11 @@ shell_execve (command, args, env)
462fb2
 		    }
462fb2
 
462fb2
 		  nphdr = ehdr.e_phnum;
462fb2
-		  phdr = (Elf32_Phdr *) malloc (nphdr * ehdr.e_phentsize);
462fb2
+		  phdr = (Elf32_Phdr *) malloc ((size_t)nphdr * (size_t)ehdr.e_phentsize);
462fb2
 		  if (phdr != NULL)
462fb2
 		    {
462fb2
 #ifdef HAVE_PREAD
462fb2
-		      sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
462fb2
+		      sample_len = pread (fd, phdr, (size_t)nphdr * (size_t)ehdr.e_phentsize,
462fb2
 					  ehdr.e_phoff);
462fb2
 #else
462fb2
 		      if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
462fb2
@@ -5120,7 +5120,7 @@ shell_execve (command, args, env)
462fb2
 		  Elf64_Ehdr ehdr;
462fb2
 		  Elf64_Phdr *phdr;
462fb2
                   Elf64_Shdr *shdr;
462fb2
-		  int nphdr, nshdr;
462fb2
+		  Elf32_Half 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
@@ -5128,11 +5128,11 @@ shell_execve (command, args, env)
462fb2
 		  memcpy (&ehdr, sample, sizeof (Elf64_Ehdr));
462fb2
 
462fb2
 		  nshdr = ehdr.e_shnum;
462fb2
-		  shdr = (Elf64_Shdr *) malloc (nshdr * ehdr.e_shentsize);
462fb2
+		  shdr = (Elf64_Shdr *) malloc ((size_t)nshdr * (size_t)ehdr.e_shentsize);
462fb2
 		  if (shdr != NULL)
462fb2
 		    {
462fb2
 #ifdef HAVE_PREAD
462fb2
-		      sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize,
462fb2
+		      sample_len = pread (fd, shdr, (size_t)nshdr * (size_t)ehdr.e_shentsize,
462fb2
 					  ehdr.e_shoff);
462fb2
 #else
462fb2
 		      if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1)
462fb2
@@ -5174,11 +5174,11 @@ shell_execve (command, args, env)
462fb2
 		    }
462fb2
 
462fb2
 		  nphdr = ehdr.e_phnum;
462fb2
-		  phdr = (Elf64_Phdr *) malloc (nphdr * ehdr.e_phentsize);
462fb2
+		  phdr = (Elf64_Phdr *) malloc ((size_t)nphdr * (size_t)ehdr.e_phentsize);
462fb2
 		  if (phdr != NULL)
462fb2
 		    {
462fb2
 #ifdef HAVE_PREAD
462fb2
-		      sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
462fb2
+		      sample_len = pread (fd, phdr, (size_t)nphdr * (size_t)ehdr.e_phentsize,
462fb2
 					  ehdr.e_phoff);
462fb2
 #else
462fb2
 		      if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
462fb2
@@ -5200,8 +5200,8 @@ shell_execve (command, args, env)
462fb2
 
462fb2
 	      if (offset != -1)
462fb2
 		{
462fb2
-		  size_t maxlen = 0;
462fb2
-		  size_t actlen = 0;
462fb2
+		  ssize_t maxlen = 0;
462fb2
+		  ssize_t actlen = 0;
462fb2
 		  char *interp = NULL;
462fb2
 
462fb2
 		  do
462fb2
@@ -5250,7 +5250,8 @@ shell_execve (command, args, env)
462fb2
 	    }
462fb2
 #endif
462fb2
 #if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
462fb2
-	  close (fd);
462fb2
+          if (fd >= 0)
462fb2
+	    close (fd);
462fb2
 #endif
462fb2
 	  errno = i;
462fb2
 	  file_error (command);