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

some times RecalculateChecksum panic error: slice bounds out of range [36:0]goroutine 166 #135

Open
introspection3 opened this issue Aug 3, 2024 · 1 comment
Labels
bug Something isn't working needs-info Needs more info from user to classify the issue

Comments

@introspection3
Copy link

introspection3 commented Aug 3, 2024

func (data *Packet) RecalculateChecksum() {
	const (
		IPProtocolTCP = 6
		IPProtocolUDP = 17
	)

	if data.IsIPv6 {
		// TODO
	} else {
		ipHeaderLen := int(data.Packet[0]&0x0f) << 2
		copy(data.Packet[ipv4offsetChecksum:], []byte{0, 0})
		ipChecksum := checksumIPv4Header(data.Packet[:ipHeaderLen])
		binary.BigEndian.PutUint16(data.Packet[ipv4offsetChecksum:], ipChecksum)

		switch protocol := data.Packet[9]; protocol {
		case IPProtocolTCP:
			tcpOffsetChecksum := ipHeaderLen + 16
			copy(data.Packet[tcpOffsetChecksum:], []byte{0, 0})
			checksum := checksumIPv4TCPUDP(data.Packet[ipHeaderLen:], uint32(protocol), data.Src, data.Dst)
			binary.BigEndian.PutUint16(data.Packet[tcpOffsetChecksum:], checksum)
		case IPProtocolUDP:
			udpOffsetChecksum := ipHeaderLen + 6
			copy(data.Packet[udpOffsetChecksum:], []byte{0, 0})
			checksum := checksumIPv4TCPUDP(data.Packet[ipHeaderLen:], uint32(protocol), data.Src, data.Dst)
			binary.BigEndian.PutUint16(data.Packet[udpOffsetChecksum:], checksum)
		}
	}
}

(*Packet).RecalculateChecksum(0x40016ae008)
error: slice bounds out of range [36:0]
binary.BigEndian.PutUint16(data.Packet[tcpOffsetChecksum:], checksum) !!!!!!!!!!!

@pymq
Copy link
Member

pymq commented Oct 13, 2024

Hi @introspection3, thanks for the report. Do you know how to reproduce it? Maybe you know what protocols you are using with VPN? What version of awl and OS platform are you using?

@pymq pymq added bug Something isn't working needs-info Needs more info from user to classify the issue labels Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-info Needs more info from user to classify the issue
Projects
None yet
Development

No branches or pull requests

2 participants