panic #7

Closed
opened 2020-06-29 07:34:24 +03:00 by MarlikAlmighty · 11 comments
MarlikAlmighty commented 2020-06-29 07:34:24 +03:00 (Migrated from github.com)

The code from the example/client/ folder does not work.

First I start the server, then the client:

go run ./... localhost:6900 "" "" and getting it

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

goroutine 1 [running]:
github.com/unistack-org/go-rfb.(*DefaultClientSecurityHandler).Handle(0x6c4180, 0x5a9b20, 0xc00006a500, 0x0, 0x0)
/home/marlik/go/pkg/mod/github.com/unistack-org/go-rfb@v0.0.0-20200122230427-c00b8c7ae0e7/handlers.go:149 +0x417
github.com/unistack-org/go-rfb.Connect(0x5a87e0, 0xc00009e000, 0x5a9740, 0xc000010010, 0xc000068000, 0x0, 0xc000010010, 0x0)
/home/marlik/go/pkg/mod/github.com/unistack-org/go-rfb@v0.0.0-20200122230427-c00b8c7ae0e7/client.go:37 +0x117
main.main()
/home/marlik/go/src/clientVNC/main.go:40 +0x46d
exit status 2

The code from the example/client/ folder does not work. First I start the server, then the client: go run ./... localhost:6900 "" "" and getting it panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x51a147] goroutine 1 [running]: github.com/unistack-org/go-rfb.(*DefaultClientSecurityHandler).Handle(0x6c4180, 0x5a9b20, 0xc00006a500, 0x0, 0x0) /home/marlik/go/pkg/mod/github.com/unistack-org/go-rfb@v0.0.0-20200122230427-c00b8c7ae0e7/handlers.go:149 +0x417 github.com/unistack-org/go-rfb.Connect(0x5a87e0, 0xc00009e000, 0x5a9740, 0xc000010010, 0xc000068000, 0x0, 0xc000010010, 0x0) /home/marlik/go/pkg/mod/github.com/unistack-org/go-rfb@v0.0.0-20200122230427-c00b8c7ae0e7/client.go:37 +0x117 main.main() /home/marlik/go/src/clientVNC/main.go:40 +0x46d exit status 2
MarlikAlmighty commented 2020-06-29 07:39:54 +03:00 (Migrated from github.com)

It seems to me to pass command line arguments through flags, a good idea.

It seems to me to pass command line arguments through flags, a good idea.
vtolstov commented 2020-06-29 11:26:46 +03:00 (Migrated from github.com)

Thanks I'll look at this

Thanks I'll look at this
vtolstov commented 2020-06-29 14:01:43 +03:00 (Migrated from github.com)

please, provide full example of main.go

please, provide full example of main.go
vtolstov commented 2020-06-29 14:02:15 +03:00 (Migrated from github.com)

looks like you pass nil net.Conn to Connect func

looks like you pass nil net.Conn to Connect func
vtolstov commented 2020-06-29 14:04:20 +03:00 (Migrated from github.com)

i'm add check for nil net.Conn in Connect func

i'm add check for nil net.Conn in Connect func
MarlikAlmighty commented 2020-06-29 15:10:34 +03:00 (Migrated from github.com)

please, provide full example of main.go

package main

import (
	"context"
	"log"
	"net"
	"os"
	"time"

	vnc "github.com/unistack-org/go-rfb"
)

func main() {
	// Establish TCP connection to VNC server.
	nc, err := net.DialTimeout("tcp", os.Args[1], 5*time.Second)
	if err != nil {
		log.Fatalf("Error connecting to VNC host. %v", err)
	}

	// Negotiate connection with the server.
	cchServer := make(chan vnc.ServerMessage)
	cchClient := make(chan vnc.ClientMessage)
	errorCh := make(chan error)

	ccfg := &vnc.ClientConfig{
		SecurityHandlers: []vnc.SecurityHandler{
			&vnc.ClientAuthATEN{
				Username: []byte(os.Args[2]),
				Password: []byte(os.Args[3]),
			}},
		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 {
		log.Fatalf("Error negotiating connection to VNC host. %v", err)
	}

	// Process messages coming in on the ServerMessage channel.
	for {
		select {
		case err := <-errorCh:
			panic(err)
		case msg := <-cchClient:
			log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
		case msg := <-cchServer:
			log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg)
		}
	}
	cc.Wait()
}
> please, provide full example of main.go ``` package main import ( "context" "log" "net" "os" "time" vnc "github.com/unistack-org/go-rfb" ) func main() { // Establish TCP connection to VNC server. nc, err := net.DialTimeout("tcp", os.Args[1], 5*time.Second) if err != nil { log.Fatalf("Error connecting to VNC host. %v", err) } // Negotiate connection with the server. cchServer := make(chan vnc.ServerMessage) cchClient := make(chan vnc.ClientMessage) errorCh := make(chan error) ccfg := &vnc.ClientConfig{ SecurityHandlers: []vnc.SecurityHandler{ &vnc.ClientAuthATEN{ Username: []byte(os.Args[2]), Password: []byte(os.Args[3]), }}, 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 { log.Fatalf("Error negotiating connection to VNC host. %v", err) } // Process messages coming in on the ServerMessage channel. for { select { case err := <-errorCh: panic(err) case msg := <-cchClient: log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg) case msg := <-cchServer: log.Printf("Received message type:%v msg:%v\n", msg.Type(), msg) } } cc.Wait() } ```
MarlikAlmighty commented 2020-06-29 15:10:57 +03:00 (Migrated from github.com)

cc.Wait()

Unreachable code
Inspection info: Reports code that can never be executed because there exists no control flow path to the code from the rest of the program.

cc.Wait() Unreachable code Inspection info: Reports code that can never be executed because there exists no control flow path to the code from the rest of the program.
MarlikAlmighty commented 2020-06-29 15:21:26 +03:00 (Migrated from github.com)

client.go

	for _, h := range cfg.Handlers {
		if err := h.Handle(conn); err != nil { // ERROR HERE
			conn.Close()
			cfg.ErrorCh <- err
			return nil, err
		}
	}
client.go ``` for _, h := range cfg.Handlers { if err := h.Handle(conn); err != nil { // ERROR HERE conn.Close() cfg.ErrorCh <- err return nil, err } } ```
vtolstov commented 2020-06-29 16:02:32 +03:00 (Migrated from github.com)

yes, i'm fix it now, please wait

yes, i'm fix it now, please wait
vtolstov commented 2020-06-29 16:42:11 +03:00 (Migrated from github.com)

please check the gist: https://gist.github.com/110bb281e332a83d65b2318b6cf8c9b2
simply worker loop must be before vnc.Connect, other fixes in master branch of go-rfb (please use latest master)

please check the gist: https://gist.github.com/110bb281e332a83d65b2318b6cf8c9b2 simply worker loop must be before vnc.Connect, other fixes in master branch of go-rfb (please use latest master)
MarlikAlmighty commented 2020-06-29 18:21:07 +03:00 (Migrated from github.com)

please check the gist: https://gist.github.com/110bb281e332a83d65b2318b6cf8c9b2
simply worker loop must be before vnc.Connect, other fixes in master branch of go-rfb (please use latest master)

Works! Thank.

> please check the gist: https://gist.github.com/110bb281e332a83d65b2318b6cf8c9b2 > simply worker loop must be before vnc.Connect, other fixes in master branch of go-rfb (please use latest master) Works! Thank.
Sign in to join this conversation.
No description provided.