go-tproxy icon indicating copy to clipboard operation
go-tproxy copied to clipboard

laddr required to be != nil

Open ghost opened this issue 7 years ago • 2 comments

I was trying to integrate (didn't actually need to at then end of the day) and found that if I passed an laddr as nil, though the method doc string says that should work, I would get panics because it looksl ike the laddr can be referenced in some of the private methods without checking for being nil.

Sorry I don't have the dumps from it but I was definitely on latest and hitting panics (mostly this is an FYI)

ghost avatar Apr 04 '18 14:04 ghost

@enckse any code example would help to understand what you are talking about.

elico avatar May 11 '20 19:05 elico

This:

package main

import (
	"fmt"
	"net"
	proxy "github.com/LiamHaworth/go-tproxy"
)

func main() {
	raddr := net.UDPAddr{IP: net.IP{127, 0, 0, 1}}
	//laddr := net.UDPAddr{IP: net.IP{127, 0, 0, 1}}

	p, err := proxy.DialUDP("TEST", nil, &raddr)
	if err != nil {
		panic(fmt.Sprintf("%v", err))
	}
	defer p.Close()
}

will result in:

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

goroutine 1 [running]:
github.com/LiamHaworth/go-tproxy.udpAddrToSocketAddr(0x0, 0x10c2f8, 0x400001e020, 0x0, 0x0)
...

Where as the DialUDP doc currently says

If laddr is not nil, it is used as the local address for the connection.

seanenck avatar Aug 07 '21 14:08 seanenck