libselinux: restorecon: avoid printing NULL pointer

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>
This commit is contained in:
Christian Göttsche 2022-06-07 19:00:35 +02:00 committed by Nicolas Iooss
parent 8cc529af51
commit 956bda08f6
No known key found for this signature in database
GPG Key ID: ACE831CD793E2C98
1 changed files with 3 additions and 1 deletions

View File

@ -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)