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

Running a program with root privileges resulted in the runtime error: invalid memory address or nil pointer dereference #3120

Closed
FizLast opened this issue Jul 4, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@FizLast
Copy link

FizLast commented Jul 4, 2022

Describe the bug:

I need to run program with root privileges for execution some bash command in runtime, but if program has system tray support It crushes.

To Reproduce:

  1. Compile the code with command "sudo go run main.go"
  2. See error

Example code:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/driver/desktop"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("SysTray")

	if desk, ok := a.(desktop.App); ok {
		m := fyne.NewMenu("MyApp",
			fyne.NewMenuItem("Show", func() {
				w.Show()
			}))
		desk.SetSystemTrayMenu(m)
	}

	w.SetContent(widget.NewLabel("Fyne System Tray"))
	w.SetCloseIntercept(func() {
		w.Hide()
	})
	w.ShowAndRun()
}

Device (please complete the following information):

  • OS: Linux Ubuntu
  • Version: 22.04 LTS (Jammy Jellyfish)
  • Go version: go1.18.1
  • Fyne version: v2.2.1
@FizLast FizLast added the unverified A bug that has been reported but not verified label Jul 4, 2022
@Jacalz
Copy link
Member

Jacalz commented Jul 4, 2022

Would you mind sharing the stack trace as well? Without it, we don’t know what or where it is crashing.

Also, I would suggest against running sudo go run as you are running both the compilation step and the execution with sudo. It is better to build the binary normally and then run with sudo if you have to.

@FizLast
Copy link
Author

FizLast commented Jul 4, 2022

Oh, I'm sorry, there is stack trace:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x70 pc=0x8cfb76]

goroutine 1 [running, locked to thread]:
github.com/godbus/dbus/v5.(*Conn).export(0xc0005f3860?, 0xc0005f3830?, {0xa138af?, 0x6?}, {0xa1b4de?, 0x10?}, 0xb?)
        /home/fizlast/go/pkg/mod/github.com/godbus/dbus/v5@v5.1.0/export.go:383 +0x36
github.com/godbus/dbus/v5.(*Conn).exportMethodTable(0x984a80?, 0xc0005f3a88?, {0xa138af?, 0x13?}, {0xa1b4de?, 0x1a?}, 0x30?)
        /home/fizlast/go/pkg/mod/github.com/godbus/dbus/v5@v5.1.0/export.go:367 +0x11b
github.com/godbus/dbus/v5.(*Conn).ExportSubtreeMethodTable(...)
        /home/fizlast/go/pkg/mod/github.com/godbus/dbus/v5@v5.1.0/export.go:346
fyne.io/systray/internal/generated/notifier.ExportStatusNotifierItem(0x0?, {0xa138af, 0x13}, {0xb0bb20?, 0x117bcd0})
        /home/fizlast/go/pkg/mod/fyne.io/systray@v1.10.1-0.20220621085403-9a2652634e93/internal/generated/notifier/status_notifier_item.go:192 +0x338
fyne.io/systray.nativeStart()
        /home/fizlast/go/pkg/mod/fyne.io/systray@v1.10.1-0.20220621085403-9a2652634e93/systray_unix.go:168 +0x69
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).runGL(0xc0003e0620)
        /home/fizlast/go/pkg/mod/fyne.io/fyne/v2@v2.2.2/internal/driver/glfw/loop.go:117 +0xdb
fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).Run(0xc0000003c0?)
        /home/fizlast/go/pkg/mod/fyne.io/fyne/v2@v2.2.2/internal/driver/glfw/driver.go:164 +0x33
fyne.io/fyne/v2/internal/driver/glfw.(*window).ShowAndRun(0xc0000003c0)
        /home/fizlast/go/pkg/mod/fyne.io/fyne/v2@v2.2.2/internal/driver/glfw/window.go:230 +0x2c
main.main()
        /home/fizlast/projects/temp/main.go:26 +0x236

And thanks for the advice.

@Jacalz
Copy link
Member

Jacalz commented Jul 4, 2022

Hmm. It looks to me like the crash is in https://github.com/godbus/dbus. Does the same crash happen if you remove the system tray? If it doesn't you can try sending a notification (using app.SendNotification).

@andydotxyz
Copy link
Member

My guess would be that due to a security model the root user cannot connect to the dbus service.
We should not crash in this scenario, good to know if notifications suffers the same as you say @Jacalz.

@FizLast
Copy link
Author

FizLast commented Jul 4, 2022

Yeah, everything works fine without system tray. As you said, I checked app.SendNotification() with root privileges, and it casted the error:

2022/07/04 18:21:56 Fyne error:  Unable to connect to session D-Bus
2022/07/04 18:21:56   Cause: exec: "dbus-launch": executable file not found in $PATH
2022/07/04 18:21:56   At: /home/fizlast/go/pkg/mod/fyne.io/fyne/v2@v2.2.2/app/app_xdg.go:38

Example code:

package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.New()
	w := a.NewWindow("SysTray")
	a.SendNotification(fyne.NewNotification("foo", "bar"))
	w.SetContent(widget.NewLabel("Fyne System Tray"))
	w.SetCloseIntercept(func() {
		w.Hide()
	})
	w.ShowAndRun()
}

@Jacalz
Copy link
Member

Jacalz commented Jul 4, 2022

Thanks for helping us narrowing down the issue. I suspect that there is some check that notifications are doing but systray doesn't.

@Bluebugs
Copy link
Contributor

Bluebugs commented Jul 4, 2022

The notification code is slightly simpler as it is only a one of call. So it connect and check the connection before each notification. Less trouble there.

It might be possible to have a process running as root access the same dbus path, but really it doesn't feel right. I would recommend building things in a two process way. One not root running the UI and one running as root, and making them communicate via some kind of protocol (could be the input/output of a process, a socket, ...). That would be a bit more align with Linux security practice.

@andydotxyz
Copy link
Member

Fixed on develop

andydotxyz added a commit to andydotxyz/fyne that referenced this issue Feb 8, 2023
@Jacalz Jacalz added bug Something isn't working and removed unverified A bug that has been reported but not verified labels May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants