diff mbox series

[4/4] selinux: set missing errno in failure branch

Message ID 20241018151300.445618-4-cgoettsche@seltendoof.de (mailing list archive)
State New
Headers show
Series [1/4] libselinux: avoid errno modification by fclose(3) | expand

Commit Message

Christian Göttsche Oct. 18, 2024, 3:13 p.m. UTC
From: Christian Göttsche <cgzones@googlemail.com>

Set errno in open_file() if rolling_append(), which does not set errno,
failed, since transitive callers might rely on it.

Reported-by: clang-analyzer
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libselinux/src/label_file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
index 40628e2c..b9c3be2a 100644
--- a/libselinux/src/label_file.c
+++ b/libselinux/src/label_file.c
@@ -563,8 +563,10 @@  static FILE *open_file(const char *path, const char *suffix,
 		/* This handles the case if suffix is null */
 		path = rolling_append(stack_path, fdetails[i].suffix,
 				      sizeof(stack_path));
-		if (!path)
+		if (!path) {
+			errno = ENOMEM;
 			return NULL;
+		}
 
 		rc = stat(path, &fdetails[i].sb);
 		if (rc)