rcolebaugh / rpms / bash

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