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