Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] nil pointer panic when calling role related functions with no role definition model #1369

Closed
MuZhou233 opened this issue Mar 1, 2024 · 2 comments · Fixed by #1389 · May be fixed by ccccrrrr/casbin#1
Closed

[Bug] nil pointer panic when calling role related functions with no role definition model #1369

MuZhou233 opened this issue Mar 1, 2024 · 2 comments · Fixed by #1389 · May be fixed by ccccrrrr/casbin#1

Comments

@MuZhou233
Copy link
Contributor

Describe the bug
Currently role_definition is an optional section in the model definitions and the role assertions (model["g"]) won't be initialized if it is omited. However, the other parts of the code won't check if it is initialized before use and result in an nil pointer panic (e.g. some lines directly read model["g"]["g"] or even more without check). This affects a wide range of public and private functions.

To Reproduce
Steps to reproduce the behavior:

  1. Initialize the model with no role_definition section
  2. Call a function that related to role
  3. Some of them may return, most of them will panic

Expected behavior
The panic should not be happen. Involve nil checks to return an error rather than panic.

Additional context
According to the documentation, this is a misuse. Following the guidelines would not encounter this issue.

@casbin-bot
Copy link
Member

@tangyang9464 @JalinWang

ccccrrrr added a commit to ccccrrrr/casbin that referenced this issue Mar 24, 2024
fix: casbin#1369

Signed-off-by: ccccrrrr <zcr1006@gmail.com>
ccccrrrr added a commit to ccccrrrr/casbin that referenced this issue Mar 24, 2024
fix: casbin#1369

Signed-off-by: ccccrrrr <zcr1006@gmail.com>
Copy link

github-actions bot commented May 7, 2024

🎉 This issue has been resolved in version 2.89.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment