Blame SOURCES/0011-checkpolicy-check-before-potential-NULL-dereference.patch

83845a
From 5a10f05f53ef78c48ebce3d512960c71100073d0 Mon Sep 17 00:00:00 2001
83845a
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
83845a
Date: Tue, 6 Jul 2021 19:54:28 +0200
83845a
Subject: [PATCH] checkpolicy: check before potential NULL dereference
83845a
MIME-Version: 1.0
83845a
Content-Type: text/plain; charset=UTF-8
83845a
Content-Transfer-Encoding: 8bit
83845a
83845a
    policy_define.c: In function ‘define_te_avtab_extended_perms’:
83845a
    policy_define.c:1946:17: error: potential null pointer dereference [-Werror=null-dereference]
83845a
     1946 |         r->omit = omit;
83845a
          |                 ^
83845a
83845a
In the case of `r` being NULL, avrule_read_ioctls() would return
83845a
with its parameter `rangehead` being a pointer to NULL, which is
83845a
considered a failure in its caller `avrule_ioctl_ranges`.
83845a
So it is not necessary to alter the return value.
83845a
83845a
Found by GCC 11 with LTO enabled.
83845a
83845a
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
83845a
---
83845a
 checkpolicy/policy_define.c | 4 +++-
83845a
 1 file changed, 3 insertions(+), 1 deletion(-)
83845a
83845a
diff --git a/checkpolicy/policy_define.c b/checkpolicy/policy_define.c
83845a
index 049df55f8468..887857851504 100644
83845a
--- a/checkpolicy/policy_define.c
83845a
+++ b/checkpolicy/policy_define.c
83845a
@@ -1943,7 +1943,9 @@ int avrule_read_ioctls(struct av_ioctl_range_list **rangehead)
83845a
 		}
83845a
 	}
83845a
 	r = *rangehead;
83845a
-	r->omit = omit;
83845a
+	if (r) {
83845a
+		r->omit = omit;
83845a
+	}
83845a
 	return 0;
83845a
 error:
83845a
 	yyerror("out of memory");
83845a
-- 
83845a
2.32.0
83845a