From a9094fae2c7bcd14af7263f9bb7fbacff5bc761c Mon Sep 17 00:00:00 2001 From: Nicolas Iooss Date: Tue, 11 Apr 2017 23:46:00 +0200 Subject: [PATCH] libselinux: avoid calling strcmp() on a NULL pointer When curcon is NULL, calling strcmp(curcon, newcon) produces an undefined behavior. Avoid this by checking whether curcon is NULL beforehand. This issue has been found using clang's static analyzer. Signed-off-by: Nicolas Iooss --- libselinux/src/selinux_restorecon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c index eefd2cf8..a41fc48a 100644 --- a/libselinux/src/selinux_restorecon.c +++ b/libselinux/src/selinux_restorecon.c @@ -664,7 +664,7 @@ static int restorecon_sb(const char *pathname, const struct stat *sb, curcon = NULL; } - if (strcmp(curcon, newcon) != 0) { + if (curcon == NULL || strcmp(curcon, newcon) != 0) { if (!flags->set_specctx && curcon && (is_context_customizable(curcon) > 0)) { if (flags->verbose) {