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-next>] [day] [month] [year] [list]
Message-Id: <20230414030830.3829332-1-zenghao@kylinos.cn>
Date:   Fri, 14 Apr 2023 11:08:30 +0800
From:   Hao Zeng <zenghao@...inos.cn>
To:     skhan@...uxfoundation.org
Cc:     trenn@...e.com, shuah@...nel.org, linux-pm@...r.kernel.org,
        linux-kernel@...r.kernel.org, Hao Zeng <zenghao@...inos.cn>
Subject: [PATCH v2] cpupower:Fix resource leaks in sysfs_get_enabled()

When the read return value is equal to 1, a file handle leak will occur

Signed-off-by: Hao Zeng <zenghao@...inos.cn>
Suggested-by: Shuah Khan <skhan@...uxfoundation.org>
---
 tools/power/cpupower/lib/powercap.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/tools/power/cpupower/lib/powercap.c b/tools/power/cpupower/lib/powercap.c
index 0ce29ee4c2e4..02ec5b0bff6b 100644
--- a/tools/power/cpupower/lib/powercap.c
+++ b/tools/power/cpupower/lib/powercap.c
@@ -40,7 +40,7 @@ static int sysfs_get_enabled(char *path, int *mode)
 {
 	int fd;
 	char yes_no;
-
+	int ret = 0;
 	*mode = 0;
 
 	fd = open(path, O_RDONLY);
@@ -48,17 +48,18 @@ static int sysfs_get_enabled(char *path, int *mode)
 		return -1;
 
 	if (read(fd, &yes_no, 1) != 1) {
-		close(fd);
-		return -1;
+		ret = -1;
+		goto err;
 	}
 
-	if (yes_no == '1') {
-		*mode = 1;
-		return 0;
-	} else if (yes_no == '0') {
-		return 0;
+	if (yes_no != '1' || yes_no != '0') {
+		ret = -1;
+		goto err;
 	}
-	return -1;
+	*mode = yes_no - '0';
+err:
+	close(fd);
+	return ret;
 }
 
 int powercap_get_enabled(int *mode)
-- 
2.37.2


No virus found
		Checked by Hillstone Network AntiVirus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ