Skip to content

Commit

Permalink
fix(dbusx): 🐛 avoid nil pointer access when busRequest exists but bus…
Browse files Browse the repository at this point in the history
… conn doesn't
  • Loading branch information
joshuar committed Feb 28, 2024
1 parent 30b9ade commit 6f69316
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/linux/dbusx/dbus.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var ErrNoBus = errors.New("no D-Bus connection")

var DbusTypeMap = map[string]dbusType{
"session": 0,
"system": 1,
"system": 1,
}

type dbusType int
Expand Down Expand Up @@ -126,7 +126,7 @@ func (r *busRequest) Destination(d string) *busRequest {
// is returned.
func GetProp[P any](req *busRequest, prop string) (P, error) {
var value P
if req == nil {
if req == nil || req.bus == nil {
return value, ErrNoBus
}
obj := req.bus.conn.Object(req.dest, req.path)
Expand All @@ -141,7 +141,7 @@ func GetProp[P any](req *busRequest, prop string) (P, error) {

// SetProp sets the specific property to the specified value.
func SetProp[P any](req *busRequest, prop string, value P) error {
if req == nil {
if req == nil || req.bus == nil {
return ErrNoBus
}
v := dbus.MakeVariant(value)
Expand All @@ -154,7 +154,7 @@ func SetProp[P any](req *busRequest, prop string, value P) error {
// stored in the given type, it will return an non-nil error.
func GetData[D any](req *busRequest, method string, args ...any) (D, error) {
var data D
if req == nil {
if req == nil || req.bus == nil {
return data, ErrNoBus
}
obj := req.bus.conn.Object(req.dest, req.path)
Expand Down

0 comments on commit 6f69316

Please sign in to comment.