Blame SOURCES/bash-4.2-coverity.patch

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