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

Random crash with "panic: runtime error: index out of range [1] with length 1" in .(*HttpRequest).Tidy #262

Open
Abradox opened this issue Sep 30, 2024 · 5 comments
Labels

Comments

@Abradox
Copy link

Abradox commented Sep 30, 2024

Version

0.12.0

Operating System

Debian 12 (Raspberry Pi OS)

How are you running SpoofDPI?

I'm using Raspberry Pi OS (aarch64) based on Debian 12 and start with args:
./spoofdpi -addr 192.168.1.10

Tried to use binaries from release page, and later build by myself with latest golang 1.23.1 - no differences.

Description

Get random crashes with output:

INF 2024-09-29T14:50:58+03:00 [PROXY] created a listener on port 8080
panic: runtime error: index out of range [1] with length 1

goroutine 121257 [running]:
github.com/xvzc/SpoofDPI/packet.(*HttpRequest).Tidy(0x400011ee00)
/home/abradox/src/SpoofDPI/packet/http.go:117 +0x260
github.com/xvzc/SpoofDPI/proxy.(*Proxy).Start.func1()
/home/abradox/src/SpoofDPI/proxy/proxy.go:82 +0x278
created by github.com/xvzc/SpoofDPI/proxy.(*Proxy).Start in goroutine 7
/home/abradox/src/SpoofDPI/proxy/proxy.go:71 +0x59c

Снимок экрана от 2024-09-30 07-44-13

@Abradox Abradox added the bug label Sep 30, 2024
@Abradox
Copy link
Author

Abradox commented Sep 30, 2024

Have added an if statement to find out what is in first position of array. Will wait for this situation again to get more info...
if len(parts) == 1 {
fmt.Printf("TIDY HAS ONE ELEMENT!\n")
fmt.Printf("%s\n", parts[0])
}

Result:
TIDY HAS ONE ELEMENT!
CONNECT firebase-settings.crashlytics.com:443 HTTP/1.1

@Ledorub
Copy link
Collaborator

Ledorub commented Oct 6, 2024

What client did you use to send the request which caused panic?

@Ledorub
Copy link
Collaborator

Ledorub commented Oct 6, 2024

The error is caused by this line:

buf.WriteString(parts[1])

Here the HTTP request is split in two by an empty line.
parts := strings.Split(s, "\r\n\r\n")

The RFC 7230 Section 3 describes the HTTP message syntax:

All HTTP/1.1 messages consist of a start-line followed by a sequence
of octets in a format similar to the Internet Message Format
[RFC5322]: zero or more header fields (collectively referred to as
the "headers" or the "header section"), an empty line indicating the
end of the header section
, and an optional message body.

 HTTP-message   = start-line
                  *( header-field CRLF )
                  CRLF
                  [ message-body ]

When request does not contain an empty line (CRLF), there is only one element in the list, which makes SpoofDPI panic. The request sent by the client is malformed.

Judging from your output, the client also does not include a mandatory Host header.
RFC 7230 Section 5.4 states:

A client MUST send a Host header field in all HTTP/1.1 request
messages.

@Abradox
Copy link
Author

Abradox commented Oct 6, 2024

Yes, probably it just a bad request, but i think program should not crash anyway... There should be a way to just drop that package and close connection with client (or just ignore).

@Ledorub
Copy link
Collaborator

Ledorub commented Oct 7, 2024

should not crash anyway

Yes.

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

No branches or pull requests

2 participants