Blame SOURCES/bash-4.2-coverity.patch

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