bash/bash-4.2-coverity.patch

113 lines
3.5 KiB
Diff
Raw Normal View History

2021-05-31 20:38:12 +08:00
From 7930678ce9b0913ed355a6294f842d3e473f810d Mon Sep 17 00:00:00 2001
From: liujian <liujianliu.liu@huawei.com>
Date: Mon, 31 May 2021 22:43:51 +0800
Subject: [PATCH] bash-4.2-coverity
---
execute_cmd.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
2019-09-30 10:32:12 -04:00
diff --git a/execute_cmd.c b/execute_cmd.c
2021-05-31 20:38:12 +08:00
index 99674df..657c047 100644
2019-09-30 10:32:12 -04:00
--- a/execute_cmd.c
+++ b/execute_cmd.c
2021-05-31 20:38:12 +08:00
@@ -5886,7 +5886,7 @@ shell_execve (command, args, env)
2019-09-30 10:32:12 -04:00
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
2021-05-31 20:38:12 +08:00
@@ -5894,12 +5894,12 @@ shell_execve (command, args, env)
2019-09-30 10:32:12 -04:00
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)
2021-05-31 20:38:12 +08:00
@@ -5941,11 +5941,11 @@ shell_execve (command, args, env)
2019-09-30 10:32:12 -04:00
}
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)
2021-05-31 20:38:12 +08:00
@@ -5970,7 +5970,7 @@ shell_execve (command, args, env)
2019-09-30 10:32:12 -04:00
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
2021-05-31 20:38:12 +08:00
@@ -5978,11 +5978,11 @@ shell_execve (command, args, env)
2019-09-30 10:32:12 -04:00
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)
2021-05-31 20:38:12 +08:00
@@ -6024,11 +6024,11 @@ shell_execve (command, args, env)
2019-09-30 10:32:12 -04:00
}
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)
2021-05-31 20:38:12 +08:00
@@ -6050,8 +6050,8 @@ shell_execve (command, args, env)
2019-09-30 10:32:12 -04:00
if (offset != -1)
{
- size_t maxlen = 0;
- size_t actlen = 0;
+ ssize_t maxlen = 0;
+ ssize_t actlen = 0;
char *interp = NULL;
do
2021-05-31 20:38:12 +08:00
@@ -6100,7 +6100,8 @@ shell_execve (command, args, env)
2019-09-30 10:32:12 -04:00
}
#endif
#if defined (HAVE_HASH_BANG_EXEC) || defined (HAVE_ELF_H)
- close (fd);
2021-05-31 20:38:12 +08:00
+ if (fd >= 0)
2019-09-30 10:32:12 -04:00
+ close (fd);
#endif
2021-05-31 20:38:12 +08:00
errno = i;
2019-09-30 10:32:12 -04:00
--
2021-05-31 20:38:12 +08:00
2.23.0