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

Sometimes app crashes #11

Open
DeadNumbers opened this issue Feb 27, 2020 · 4 comments
Open

Sometimes app crashes #11

DeadNumbers opened this issue Feb 27, 2020 · 4 comments

Comments

@DeadNumbers
Copy link

Hi! I'm tested this code on Arch Linux, Gnome and Vino (https://wiki.gnome.org/Projects/Vino).
Code from examples/client

package main

import (
	"context"
	"fmt"
	"net"
	"runtime"
	"time"

	vnc "github.com/amitbet/vnc2video"
	"github.com/amitbet/vnc2video/logger"
)

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	nc, err := net.DialTimeout("tcp", "127.0.0.1:5900", 60*time.Second)
	if err != nil {
		logger.Fatalf("Error connecting to VNC host. %v", err)
	}

	logger.Tracef("starting up the client, connecting to: %s", "127.0.0.1:5900")
	cchServer := make(chan vnc.ServerMessage)
	cchClient := make(chan vnc.ClientMessage)
	errorCh := make(chan error)

	ccfg := &vnc.ClientConfig{
		SecurityHandlers: []vnc.SecurityHandler{
			&vnc.ClientAuthVNC{Password: []byte("12345")},
			&vnc.ClientAuthNone{},
		},
		DrawCursor:      true,
		PixelFormat:     vnc.PixelFormat32bit,
		ClientMessageCh: cchClient,
		ServerMessageCh: cchServer,
		Messages:        vnc.DefaultServerMessages,
		Encodings: []vnc.Encoding{
			&vnc.RawEncoding{},
		},
		ErrorCh: errorCh,
	}

	cc, err := vnc.Connect(context.Background(), nc, ccfg)
	if err != nil {
		logger.Fatalf("Error negotiating connection to VNC host. %v", err)
	}
	fmt.Println(string(cc.DesktopName()))
}

Traceback

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

goroutine 8 [running]:
github.com/amitbet/vnc2video.(*VncCanvas).RemoveCursor(0x0, 0xc0000727e0, 0xc000044f07)
	github.com/amitbet/vnc2video/encoding_util.go:61 +0x26
github.com/amitbet/vnc2video.(*DefaultClientMessageHandler).Handle.func2(0xc00001c550, 0x5a4e80, 0xc000136500, 0xc0000126d0, 0xc000134000, 0xc0000727e0)
	github.com/amitbet/vnc2video/client.go:303 +0x28a
created by github.com/amitbet/vnc2video.(*DefaultClientMessageHandler).Handle
	github.com/amitbet/vnc2video/client.go:285 +0x2b8

Sometimes app print desktop name, but sometimes app crashed.
изображение

@DeadNumbers
Copy link
Author

Any ideas?

@amitbet
Copy link
Owner

amitbet commented Mar 21, 2020

well, it looks like there is some nil pointer in there :)
these situations really need a debugger attached.. remote advice according to an error won't do a lot of good.
Would love to be of more help, if you have more info..

I never tested this on archlinux, and more importantly I don't know which vnc server this is working with.
Sometimes they use some messages that I haven't programmed in, which makes the decoder derail (this is a binary stream after all), and sometimes there can be a message that sends a legit payload that I have not planned for.
In VncProxy I think I have worked out most of these kinks, but this project was never in production.
if you manage to debug it, it'll be glad to merge your code back in.

@amitbet
Copy link
Owner

amitbet commented Mar 21, 2020

I see Vino is a VNC-Server...
I used tight to program this - so that would be a more compatible option if you don't have the time to debug.

@gyuchang
Copy link

gyuchang commented May 8, 2020

@DeadNumbers

It seems that sometimes DefaultClientMessageHandler is called before the canvas is initialized.

vnc2video/client.go

Lines 37 to 49 in 9d50b9d

for _, h := range cfg.Handlers {
if err := h.Handle(conn); err != nil {
logger.Error("Handshake failed, check that server is running: ", err)
conn.Close()
cfg.ErrorCh <- err
return nil, err
}
}
canvas := NewVncCanvas(int(conn.Width()), int(conn.Height()))
canvas.DrawCursor = cfg.DrawCursor
conn.Canvas = canvas
return conn, nil

DefaultClientMessageHandler is set up and started in line 38 and canvas is set up in line 48.

See #14 for my proposed fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants