libselinux/backport-libselinux-restorecon-avoid-printing-NULL-pointer.patch
2022-10-09 14:33:09 +08:00

37 lines
1.2 KiB
Diff

From 956bda08f6183078f13b70f6aa27d0529a3ec20a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
Date: Tue, 7 Jun 2022 19:00:35 +0200
Subject: [PATCH] libselinux: restorecon: avoid printing NULL pointer
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The variable `curcon` is NULL in case the file has no current security
context. Most C standard libraries handle it fine, avoid it nonetheless
for standard conformance.
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
src/selinux_restorecon.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/selinux_restorecon.c b/src/selinux_restorecon.c
index 66e6a4a2..2d24559f 100644
--- a/src/selinux_restorecon.c
+++ b/src/selinux_restorecon.c
@@ -744,7 +744,9 @@ static int restorecon_sb(const char *pathname, const struct stat *sb,
selinux_log(SELINUX_INFO,
"%s %s from %s to %s\n",
updated ? "Relabeled" : "Would relabel",
- pathname, curcon, newcon);
+ pathname,
+ curcon ? curcon : "<no context>",
+ newcon);
if (flags->syslog_changes && !flags->nochange) {
if (curcon)
--
2.27.0