lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221009070827.525694-2-kunyu@nfschina.com>
Date:   Sun,  9 Oct 2022 15:08:28 +0800
From:   Li kunyu <kunyu@...china.com>
To:     lkp@...el.com
Cc:     andrii@...nel.org, ast@...nel.org, bpf@...r.kernel.org,
        daniel@...earbox.net, haoluo@...gle.com, john.fastabend@...il.com,
        jolsa@...nel.org, kbuild-all@...ts.01.org, kpsingh@...nel.org,
        kunyu@...china.com, linux-kernel@...r.kernel.org,
        martin.lau@...ux.dev, sdf@...gle.com, song@...nel.org, yhs@...com
Subject: [PATCH] lib: bpf: Optimized variable usage in the btf_parse_elf function

The following changes were made in the btf_parse_elf function:
1. The initialization assignments of err, fd, scn and elf variables are
removed, and they do not affect function security after analysis.
2. Remove unnecessary assignments to err variable (-error).

Signed-off-by: Li kunyu <kunyu@...china.com>
---
 tools/lib/bpf/btf.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 2d14f1a52d7a..fa9d5fa03da4 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -910,10 +910,10 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf,
 				 struct btf_ext **btf_ext)
 {
 	Elf_Data *btf_data = NULL, *btf_ext_data = NULL;
-	int err = 0, fd = -1, idx = 0;
+	int err, fd, idx = 0;
 	struct btf *btf = NULL;
-	Elf_Scn *scn = NULL;
-	Elf *elf = NULL;
+	Elf_Scn *scn;
+	Elf *elf;
 	GElf_Ehdr ehdr;
 	size_t shstrndx;
 
@@ -924,9 +924,8 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf,
 
 	fd = open(path, O_RDONLY | O_CLOEXEC);
 	if (fd < 0) {
-		err = -errno;
 		pr_warn("failed to open %s: %s\n", path, strerror(errno));
-		return ERR_PTR(err);
+		return ERR_PTR(-errno);
 	}
 
 	err = -LIBBPF_ERRNO__FORMAT;
@@ -987,8 +986,6 @@ static struct btf *btf_parse_elf(const char *path, struct btf *base_btf,
 		}
 	}
 
-	err = 0;
-
 	if (!btf_data) {
 		err = -ENOENT;
 		goto done;
-- 
2.18.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ