From a6943690e9ced4e83241b23f468fa648a88113d2 Mon Sep 17 00:00:00 2001 From: Packit Date: Sep 17 2020 16:37:14 +0000 Subject: Apply patch bash-4.2-coverity.patch patch_name: bash-4.2-coverity.patch present_in_specfile: true location_in_specfile: 38 --- diff --git a/execute_cmd.c b/execute_cmd.c index c9cf609..63a332a 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -5561,7 +5561,7 @@ shell_execve (command, args, env) Elf32_Ehdr ehdr; Elf32_Phdr *phdr; Elf32_Shdr *shdr; - int nphdr, nshdr; + Elf32_Half nphdr, nshdr; /* We have to copy the data since the sample buffer might not be aligned correctly to be accessed as @@ -5569,12 +5569,12 @@ shell_execve (command, args, env) memcpy (&ehdr, sample, sizeof (Elf32_Ehdr)); nshdr = ehdr.e_shnum; - shdr = (Elf32_Shdr *) malloc (nshdr * ehdr.e_shentsize); + shdr = (Elf32_Shdr *) malloc ((size_t)nshdr * (size_t)ehdr.e_shentsize); if (shdr != NULL) { #ifdef HAVE_PREAD - sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize, + sample_len = pread (fd, shdr, (size_t)nshdr * (size_t)ehdr.e_shentsize, ehdr.e_shoff); #else if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1) @@ -5616,11 +5616,11 @@ shell_execve (command, args, env) } nphdr = ehdr.e_phnum; - phdr = (Elf32_Phdr *) malloc (nphdr * ehdr.e_phentsize); + phdr = (Elf32_Phdr *) malloc ((size_t)nphdr * (size_t)ehdr.e_phentsize); if (phdr != NULL) { #ifdef HAVE_PREAD - sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize, + sample_len = pread (fd, phdr, (size_t)nphdr * (size_t)ehdr.e_phentsize, ehdr.e_phoff); #else if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1) @@ -5645,7 +5645,7 @@ shell_execve (command, args, env) Elf64_Ehdr ehdr; Elf64_Phdr *phdr; Elf64_Shdr *shdr; - int nphdr, nshdr; + Elf32_Half nphdr, nshdr; /* We have to copy the data since the sample buffer might not be aligned correctly to be accessed as @@ -5653,11 +5653,11 @@ shell_execve (command, args, env) memcpy (&ehdr, sample, sizeof (Elf64_Ehdr)); nshdr = ehdr.e_shnum; - shdr = (Elf64_Shdr *) malloc (nshdr * ehdr.e_shentsize); + shdr = (Elf64_Shdr *) malloc ((size_t)nshdr * (size_t)ehdr.e_shentsize); if (shdr != NULL) { #ifdef HAVE_PREAD - sample_len = pread (fd, shdr, nshdr * ehdr.e_shentsize, + sample_len = pread (fd, shdr, (size_t)nshdr * (size_t)ehdr.e_shentsize, ehdr.e_shoff); #else if (lseek (fd, ehdr.e_shoff, SEEK_SET) != -1) @@ -5699,11 +5699,11 @@ shell_execve (command, args, env) } nphdr = ehdr.e_phnum; - phdr = (Elf64_Phdr *) malloc (nphdr * ehdr.e_phentsize); + phdr = (Elf64_Phdr *) malloc ((size_t)nphdr * (size_t)ehdr.e_phentsize); if (phdr != NULL) { #ifdef HAVE_PREAD - sample_len = pread (fd, phdr, nphdr * ehdr.e_phentsize, + sample_len = pread (fd, phdr, (size_t)nphdr * (size_t)ehdr.e_phentsize, ehdr.e_phoff); #else if (lseek (fd, ehdr.e_phoff, SEEK_SET) != -1) @@ -5725,8 +5725,8 @@ shell_execve (command, args, env) if (offset != -1) { - size_t maxlen = 0; - size_t actlen = 0; + ssize_t maxlen = 0; + ssize_t actlen = 0; char *interp = NULL; do @@ -5775,7 +5775,8 @@ shell_execve (command, args, env) } #endif #if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H) - close (fd); + if (fd >= 0) + close (fd); #endif errno = i; file_error (command);