nalika / rpms / bash

Forked from rpms/bash 2 years ago
Clone

Blame SOURCES/bash-4.2-coverity.patch

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