[PATCH 2/2] libsepol: Prevent NULL dereference in hierarchy_add_type_callback

Stephen Smalley <[email protected]>
Newsgroups org.kernel.vger.selinux
Message-ID <[email protected]>
Depending on policy version, the type_val_to_name[] array may contain
NULL values. Check for and handle them.

Reported-by: Chen Gong <[email protected]>
Signed-off-by: Stephen Smalley <[email protected]>
---
 libsepol/src/hierarchy.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libsepol/src/hierarchy.c b/libsepol/src/hierarchy.c
index 5e19ddda..0499bdfa 100644
--- a/libsepol/src/hierarchy.c
+++ b/libsepol/src/hierarchy.c
@@ -634,6 +634,8 @@ int bounds_check_users(sepol_handle_t *handle, policydb_t *p)
 				p->p_##prefix##_val_to_name[datum->s.value -     \
 							    1];                  \
                                                                                  \
+			if (!datum_name)                                         \
+				return 0;                                        \
 			tmp = strrchr(datum_name, '.');                          \
 			/* no '.' means it has no parent */                      \
 			if (!tmp)                                                \
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.