svashisht / rpms / bash

Forked from rpms/bash 4 years ago
Clone

Blame SOURCES/bash-4.2-coverity.patch

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