1 Star 0 Fork 39

wuzx/bash

forked from src-openEuler/bash 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
bash-4.2-coverity.patch 3.55 KB
一键复制 编辑 原始数据 按行查看 历史
JeanLeo 提交于 2021-05-31 20:38 . upgrade to 5.1
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(-)
diff --git a/execute_cmd.c b/execute_cmd.c
index 99674df..657c047 100644
--- a/execute_cmd.c
+++ b/execute_cmd.c
@@ -5886,7 +5886,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
@@ -5894,12 +5894,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)
@@ -5941,11 +5941,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)
@@ -5970,7 +5970,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
@@ -5978,11 +5978,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)
@@ -6024,11 +6024,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)
@@ -6050,8 +6050,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
@@ -6100,7 +6100,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;
--
2.23.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuzx065891/bash.git
git@gitee.com:wuzx065891/bash.git
wuzx065891
bash
bash
master

搜索帮助