42 lines
1.1 KiB
Diff
42 lines
1.1 KiB
Diff
|
|
From c8b1f5928236e9ed3192a4393cb563cb718ccca4 Mon Sep 17 00:00:00 2001
|
||
|
|
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
|
||
|
|
Date: Mon, 29 Apr 2024 18:38:59 +0200
|
||
|
|
Subject: [PATCH] libselinux: free empty scandir(3) result
|
||
|
|
MIME-Version: 1.0
|
||
|
|
Content-Type: text/plain; charset=UTF-8
|
||
|
|
Content-Transfer-Encoding: 8bit
|
||
|
|
|
||
|
|
In case scandir(3) finds no entries still free the returned result to
|
||
|
|
avoid leaking it.
|
||
|
|
|
||
|
|
Also do not override errno in case of a failure.
|
||
|
|
|
||
|
|
Reported.by: Cppcheck
|
||
|
|
|
||
|
|
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
|
||
|
|
Acked-by: James Carter <jwcart2@gmail.com>
|
||
|
|
---
|
||
|
|
src/booleans.c | 6 +++++-
|
||
|
|
1 file changed, 5 insertions(+), 1 deletion(-)
|
||
|
|
|
||
|
|
diff --git a/src/booleans.c b/src/booleans.c
|
||
|
|
index c557df65..1ede8e2d 100644
|
||
|
|
--- a/src/booleans.c
|
||
|
|
+++ b/src/booleans.c
|
||
|
|
@@ -53,7 +53,11 @@ int security_get_boolean_names(char ***names, int *len)
|
||
|
|
|
||
|
|
snprintf(path, sizeof path, "%s%s", selinux_mnt, SELINUX_BOOL_DIR);
|
||
|
|
*len = scandir(path, &namelist, &filename_select, alphasort);
|
||
|
|
- if (*len <= 0) {
|
||
|
|
+ if (*len < 0) {
|
||
|
|
+ return -1;
|
||
|
|
+ }
|
||
|
|
+ if (*len == 0) {
|
||
|
|
+ free(namelist);
|
||
|
|
errno = ENOENT;
|
||
|
|
return -1;
|
||
|
|
}
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|