Blame SOURCES/bash-4.2-coverity.patch

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