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 <nicolas.iooss@m4x.org>
This commit is contained in:
Nicolas Iooss 2017-04-11 23:46:00 +02:00 committed by Stephen Smalley
parent b63eb892f9
commit a9094fae2c
1 changed files with 1 additions and 1 deletions

View File

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