rcolebaugh / rpms / bash

Forked from rpms/bash a year ago
Clone

Blame SOURCES/bash-4.2-coverity.patch

bb9a7e
diff --git a/execute_cmd.c b/execute_cmd.c
bb9a7e
index a988400..412128c 100644
bb9a7e
--- a/execute_cmd.c
bb9a7e
+++ b/execute_cmd.c
bb9a7e
@@ -5760,7 +5760,7 @@ shell_execve (command, args, env)
bb9a7e
 		  Elf32_Ehdr ehdr;
bb9a7e
 		  Elf32_Phdr *phdr;
bb9a7e
                   Elf32_Shdr *shdr;
bb9a7e
-		  int nphdr, nshdr;
bb9a7e
+		  Elf32_Half nphdr, nshdr;
bb9a7e
 
bb9a7e
 		  /* We have to copy the data since the sample buffer
bb9a7e
 		     might not be aligned correctly to be accessed as
bb9a7e
@@ -5768,12 +5768,12 @@ shell_execve (command, args, env)
bb9a7e
 		  memcpy (&ehdr, sample, sizeof (Elf32_Ehdr));
bb9a7e
 
bb9a7e
 		  nshdr = ehdr.e_shnum;
bb9a7e
-		  shdr = (Elf32_Shdr *) malloc (nshdr * ehdr.e_shentsize);
bb9a7e
+		  shdr = (Elf32_Shdr *) malloc ((size_t)nshdr * (size_t)ehdr.e_shentsize);
bb9a7e
                   
bb9a7e
 		  if (shdr != NULL)
bb9a7e
 		    {
bb9a7e
 #ifdef HAVE_PREAD
bb9a7e
-		      sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize,
bb9a7e
+		      sample_len = pread (fd, shdr, (size_t)nshdr * (size_t)ehdr.e_shentsize,
bb9a7e
 					  ehdr.e_shoff);
bb9a7e
 #else
bb9a7e
 		      if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1)
bb9a7e
@@ -5815,11 +5815,11 @@ shell_execve (command, args, env)
bb9a7e
 		    }
bb9a7e
 
bb9a7e
 		  nphdr = ehdr.e_phnum;
bb9a7e
-		  phdr = (Elf32_Phdr *) malloc (nphdr * ehdr.e_phentsize);
bb9a7e
+		  phdr = (Elf32_Phdr *) malloc ((size_t)nphdr * (size_t)ehdr.e_phentsize);
bb9a7e
 		  if (phdr != NULL)
bb9a7e
 		    {
bb9a7e
 #ifdef HAVE_PREAD
bb9a7e
-		      sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
bb9a7e
+		      sample_len = pread (fd, phdr, (size_t)nphdr * (size_t)ehdr.e_phentsize,
bb9a7e
 					  ehdr.e_phoff);
bb9a7e
 #else
bb9a7e
 		      if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
bb9a7e
@@ -5844,7 +5844,7 @@ shell_execve (command, args, env)
bb9a7e
 		  Elf64_Ehdr ehdr;
bb9a7e
 		  Elf64_Phdr *phdr;
bb9a7e
                   Elf64_Shdr *shdr;
bb9a7e
-		  int nphdr, nshdr;
bb9a7e
+		  Elf32_Half nphdr, nshdr;
bb9a7e
 
bb9a7e
 		  /* We have to copy the data since the sample buffer
bb9a7e
 		     might not be aligned correctly to be accessed as
bb9a7e
@@ -5852,11 +5852,11 @@ shell_execve (command, args, env)
bb9a7e
 		  memcpy (&ehdr, sample, sizeof (Elf64_Ehdr));
bb9a7e
 
bb9a7e
 		  nshdr = ehdr.e_shnum;
bb9a7e
-		  shdr = (Elf64_Shdr *) malloc (nshdr * ehdr.e_shentsize);
bb9a7e
+		  shdr = (Elf64_Shdr *) malloc ((size_t)nshdr * (size_t)ehdr.e_shentsize);
bb9a7e
 		  if (shdr != NULL)
bb9a7e
 		    {
bb9a7e
 #ifdef HAVE_PREAD
bb9a7e
-		      sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize,
bb9a7e
+		      sample_len = pread (fd, shdr, (size_t)nshdr * (size_t)ehdr.e_shentsize,
bb9a7e
 					  ehdr.e_shoff);
bb9a7e
 #else
bb9a7e
 		      if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1)
bb9a7e
@@ -5898,11 +5898,11 @@ shell_execve (command, args, env)
bb9a7e
 		    }
bb9a7e
 
bb9a7e
 		  nphdr = ehdr.e_phnum;
bb9a7e
-		  phdr = (Elf64_Phdr *) malloc (nphdr * ehdr.e_phentsize);
bb9a7e
+		  phdr = (Elf64_Phdr *) malloc ((size_t)nphdr * (size_t)ehdr.e_phentsize);
bb9a7e
 		  if (phdr != NULL)
bb9a7e
 		    {
bb9a7e
 #ifdef HAVE_PREAD
bb9a7e
-		      sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize,
bb9a7e
+		      sample_len = pread (fd, phdr, (size_t)nphdr * (size_t)ehdr.e_phentsize,
bb9a7e
 					  ehdr.e_phoff);
bb9a7e
 #else
bb9a7e
 		      if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1)
bb9a7e
@@ -5924,8 +5924,8 @@ shell_execve (command, args, env)
bb9a7e
 
bb9a7e
 	      if (offset != -1)
bb9a7e
 		{
bb9a7e
-		  size_t maxlen = 0;
bb9a7e
-		  size_t actlen = 0;
bb9a7e
+		  ssize_t maxlen = 0;
bb9a7e
+		  ssize_t actlen = 0;
bb9a7e
 		  char *interp = NULL;
bb9a7e
 
bb9a7e
 		  do
bb9a7e
@@ -5974,7 +5974,8 @@ shell_execve (command, args, env)
bb9a7e
 	    }
bb9a7e
 #endif
bb9a7e
 #if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
bb9a7e
-	  close (fd);
bb9a7e
+          if (fd >= 0)
bb9a7e
+	    close (fd);
bb9a7e
 #endif
bb9a7e
 
bb9a7e
       errno = i;
bb9a7e
-- 
bb9a7e
2.17.2
bb9a7e