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:
parent
b63eb892f9
commit
a9094fae2c
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue