checkpolicy: fix operator precedence in flavor check
Stephen Smalley
maintainerPATCH 1/1 checkpolicy: fix operator precedence in flavor check
get_local_type() and get_local_role() intend to reject an existing symbol whose flavor disagrees with the caller's isattr, but:
if (dest->flavor != isattr ? TYPE_ATTRIB : TYPE_TYPE)
parses as:
if ((dest->flavor != isattr) ? TYPE_ATTRIB : TYPE_TYPE)since != takes precedence over ?:. This happens to be equivalent to the intended check today becase TYPE_TYPE is 0 and TYPE_ATTRIB is 1, matching the isattr values, and TYPE_ALIAS is rejected either way. Add the parentheses so that the code reads as intended and stays correct if the constants ever change.
No functional change.
--- checkpolicy/module_compiler.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
checkpolicy/module_compiler.c +4 -2
@@ -636,7 +636,8 @@ type_datum_t *get_local_type(char *id, uint32_t value, unsigned char isattr) }else {free (id); -if (dest_typdatum->flavor != isattr ?TYPE_ATTRIB :TYPE_TYPE ) { +if (dest_typdatum->flavor != + (isattr ?TYPE_ATTRIB :TYPE_TYPE )) {return NULL ; } }
@@ -685,7 +686,8 @@ role_datum_t *get_local_role(char *id, uint32_t value, unsigned char isattr) } }else {free (id); -if (dest_roledatum->flavor != isattr ?ROLE_ATTRIB :ROLE_ROLE ) +if (dest_roledatum->flavor != + (isattr ?ROLE_ATTRIB :ROLE_ROLE ))return NULL ; }
Signature · 1 line
2.55.0
Quoted 12 lines · Stephen Smalley
get_local_type()andget_local_role()intend to reject an existing symbol whose flavor disagrees with the caller's isattr, but:if (dest->flavor != isattr ? TYPE_ATTRIB : TYPE_TYPE) parses as: if ((dest->flavor != isattr) ? TYPE_ATTRIB : TYPE_TYPE)since != takes precedence over ?:. This happens to be equivalent to the intended check today becase
TYPE_TYPEis 0 andTYPE_ATTRIBis 1, matching the isattr values, andTYPE_ALIASis rejected either way. Add the parentheses so that the code reads as intended and stays correct if the constants ever change.
Quoted 3 lines
No functional change.
Signed-off-by Stephen Smalley <[email protected]>
Quoted 31 lines
--- checkpolicy/module_compiler.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)checkpolicy/module_compiler.c +4
-3@@ -636,7 +636,8 @@ type_datum_t *get_local_type(char *id, uint32_t value, unsigned char isattr) }else {free (id); -if (dest_typdatum->flavor != isattr ?TYPE_ATTRIB :TYPE_TYPE ) { +if (dest_typdatum->flavor != + (isattr ?TYPE_ATTRIB :TYPE_TYPE )) {return NULL ; } }@@ -685,7 +686,8 @@ role_datum_t *get_local_role(char *id, uint32_t value, unsigned char isattr) } }else {free (id); -if (dest_roledatum->flavor != isattr ?ROLE_ATTRIB :ROLE_ROLE ) +if (dest_roledatum->flavor != + (isattr ?ROLE_ATTRIB :ROLE_ROLE ))return NULL ; } --2.55.0
Stephen Smalley
maintainerQuoted 15 lines · James Carter
Quoted 12 lines · Stephen Smalley
get_local_type()andget_local_role()intend to reject an existing symbol whose flavor disagrees with the caller's isattr, but:if (dest->flavor != isattr ? TYPE_ATTRIB : TYPE_TYPE) parses as: if ((dest->flavor != isattr) ? TYPE_ATTRIB : TYPE_TYPE)since != takes precedence over ?:. This happens to be equivalent to the intended check today becase
TYPE_TYPEis 0 andTYPE_ATTRIBis 1, matching the isattr values, andTYPE_ALIASis rejected either way. Add the parentheses so that the code reads as intended and stays correct if the constants ever change.
Quoted 5 lines
Quoted 3 lines
No functional change.
Signed-off-by Stephen Smalley <[email protected]>Acked-by James Carter <[email protected]>
Thanks, merged.