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

When the NewEnforcer is completed, call GetRolesForUserInDomain and report the error invalid memory address or nil pointer dereference #247

Closed
GanymedeNil opened this issue Jun 26, 2019 · 1 comment
Assignees
Labels

Comments

@GanymedeNil
Copy link

code show as below

package main

import (
	"fmt"
	"github.com/casbin/casbin"
)

func main(){
	e := casbin.NewEnforcer("rbac_with_domains_model.conf")
	e.EnableLog(true)
        user:="alice"
	sub := "admin" // the user that wants to access a resource.
	dom :="domain1"

	list:=e.GetRolesForUserInDomain(user,dom)
	fmt.Println(list)
        if e.AddRoleForUserInDomain(user,sub,dom){
		list:=e.GetRolesForUserInDomain(user,dom)
		fmt.Println(list)
	}
}

Found through the tracking code, e.model["g"]["g"].RM is nil。
I am solving this problem now, but I don't know if it is a bug.

package main

import (
	"fmt"
	"github.com/casbin/casbin"
)

func main(){
	e := casbin.NewEnforcer("rbac_with_domains_model.conf")
	e.EnableLog(true)
	user:="alice"
	sub := "admin" // the user that wants to access a resource.
	dom :="domain1"
	
	if e.GetModel()["g"]["g"].RM != nil {
		list:=e.GetRolesForUserInDomain(user,dom)
		fmt.Println(list)
	}
	if e.AddRoleForUserInDomain(user,sub,dom){
		list:=e.GetRolesForUserInDomain(user,dom)
		fmt.Println(list)
	}
}
@hsluoyz
Copy link
Contributor

hsluoyz commented Jun 26, 2019

Hi @GanymedeNil , thanks for the report. It has been fixed in: b7676f1

@hsluoyz hsluoyz self-assigned this Jun 26, 2019
@hsluoyz hsluoyz added the bug label Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants