Skip to contentSkip to conversation

libsepol/cil: call cil_reset_context() when context is not NULL

PATCH In review Nicolas Iooss 2 participants 2 messages Jun 5, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: call cil_reset_context() when context is not NULL

cil_reset_context() dereferences its argument, which is thus expected not to be NULL. The if statement in cil_reset_ibpkeycon() verified the opposite condition. Fix this.

This issue has been found using clang's static analyzer.

---
 libsepol/cil/src/cil_reset_ast.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_reset_ast.c +1 -1
index 73034a97956b..dd047c8e0409 100644
@@ -290,7 +290,7 @@ static void cil_reset_filecon(struct cil_filecon *filecon)
 
 static void cil_reset_ibpkeycon(struct cil_ibpkeycon *ibpkeycon)
 {
-	if (!ibpkeycon->context)
+	if (ibpkeycon->context)
 		cil_reset_context(ibpkeycon->context);
 }
 
Signature · 1 line
2.13.0
#1 lore raw
Quoted 7 lines · Nicolas Iooss

cil_reset_context() dereferences its argument, which is thus expected not to be NULL. The if statement in cil_reset_ibpkeycon() verified the opposite condition. Fix this.

This issue has been found using clang's static analyzer.

Thanks for the report.

Quoted 10 lines
---
  libsepol/cil/src/cil_reset_ast.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_reset_ast.c +0 -0
index 73034a97956b..dd047c8e0409 100644

libsepol/cil/src/cil_reset_ast.c static void cil_reset_filecon(struct cil_filecon *filecon) · line 296

Quoted 8 lines
libsepol/cil/src/cil_reset_ast.c +1 -1
@@ -290,7 +290,7 @@ static void cil_reset_filecon(struct cil_filecon *filecon)
 
  static void cil_reset_ibpkeycon(struct cil_ibpkeycon *ibpkeycon)
  {
-	if (!ibpkeycon->context)
+	if (ibpkeycon->context)
  		cil_reset_context(ibpkeycon->context);
  }
 

The real issue is that it should be checking ibpkeycon->context_str instead.

I have merged a fix crediting you with reporting the issue.

Jim

Signature · 2 lines
James Carter <[email protected]>
National Security Agency