selinux: clarify return code in filename_trans_read_helper_compat()
PATCH 1/1 selinux: clarify return code in filename_trans_read_helper_compat()
For the "conflicting/duplicate rules" branch in filename_trans_read_helper_compat() the Smatch static checker reports:
security/selinux/ss/policydb.c:1953 filename_trans_read_helper_compat()
warn: missing error code 'rc'
While the value of rc will already always be zero here, it is not obvious that it's the case and that it's the intended return value (Smatch expects rc to be assigned within 5 lines from the goto). Therefore, add an explicit assignment just before the goto to make the intent more clear and the code less error-prone.
--- security/selinux/ss/policydb.c | 1 + 1 file changed, 1 insertion(+)
security/selinux/ss/policydb.c +1 -0
@@ -1950,6 +1950,7 @@ static int filename_trans_read_helper_compat(struct policydb *p, void *fp)if (unlikely (ebitmap_get_bit (&datum->stypes, stype -1 ))) {/* conflicting/duplicate rules are ignored */ datum =NULL ; + rc =0 ; goto out; }if (likely (datum->otype == otype))
Signature · 1 line
2.44.0
Paul Moore
maintainerQuoted 13 lines · On Apr 4, 2024 Ondrej Mosnacek <[email protected]> wrote:
For the "conflicting/duplicate rules" branch in
filename_trans_read_helper_compat()the Smatch static checker reports:
security/selinux/ss/policydb.c:1953filename_trans_read_helper_compat()
warn: missing error code 'rc'While the value of rc will already always be zero here, it is not obvious that it's the case and that it's the intended return value (Smatch expects rc to be assigned within 5 lines from the goto). Therefore, add an explicit assignment just before the goto to make the intent more clear and the code less error-prone.
Quoted 7 lines
Fixes c3a276111ea2 ("selinux: optimize storage of filename transitions")Reported-by Dan Carpenter <[email protected]>Signed-off-by Ondrej Mosnacek <[email protected]>--- security/selinux/ss/policydb.c | 1 + 1 file changed, 1 insertion(+)
As this really only impacts static analysis I don't think this rises to the level of warranting a stable tag so I'm going to merge this via the selinux/dev branch. Thanks everyone!
--
paul-moore.com