checkpolicy: abort on mismatched declarations

In case a type or role gets re-declared as an attribute abort parsing
immediately. Since yyerror() is called the variable policydb_errors is
increased and will signal an error later on.

Reported-by: oss-fuzz (issue 398527873)
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
Christian Göttsche 2025-02-25 15:33:10 +01:00 committed by James Carter
parent 9cfc7b9fff
commit 20aa2f8d58

View File

@ -291,6 +291,7 @@ static int create_role(uint32_t scope, unsigned char isattr, role_datum_t **role
if (*role && (isattr != (*role)->flavor)) {
yyerror2("Identifier %s used as both an attribute and a role",
id);
*role = NULL;
free(id);
role_datum_destroy(datum);
free(datum);
@ -428,6 +429,7 @@ static int create_type(uint32_t scope, unsigned char isattr, type_datum_t **type
if (*type && (isattr != (*type)->flavor)) {
yyerror2("Identifier %s used as both an attribute and a type",
id);
*type = NULL;
free(id);
return -1;
}