-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Due to that someone reported a crash on my app when passing very long parameters to the server i did some deeper investigation.
It turns out that this is happening in httplib.
So i tried a bit and was able to verify my finding even with your example server.cc code.
This is the env im using:
alpine64:~# g++ --version
g++ (Alpine 10.2.1_pre1) 10.2.1 20201203
With a not to long path everyting works as expected.
alpine64:~# g++ server.cc -I. -g -o server
alpine64:~# ./server
================================
GET HTTP/1.1 /tinypath
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: de,en-US;q=0.9,en;q=0.8,es;q=0.7
Connection: keep-alive
DNT: 1
Host: 192.168.0.36:8080
REMOTE_ADDR: 192.168.0.55
REMOTE_PORT: 49466
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36
--------------------------------
404 HTTP/1.1
Content-Length: 56
Content-Type: text/html
Keep-Alive: timeout=5, max=5
<p>Error Status: <span style='color:red;'>404</span></p>
But using this request it segfaults.
http://192.168.0.36:8080/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccddddddddddddddddddddddeeeeeeeeeeeeeeeeeeefffffffffffffffffffffffffffffffffffggggggggggggggggggggggggggggg
alpine64:~# ./server
Segmentation fault (core dumped)
Even without printing the headers.
The segfault is happening somewhere here:
#2023 0x00005610ffe76a3c in std::regex_match<char, std::allocator<std::__cxx11::sub_match<char const*> >, std::__cxx11::regex_traits<char> > (__s=0x7f98b1e29e70 "GET /", 'a' <repeats 195 times>..., __m=..., __re=..., __f=0) at /usr/include/c++/10.2.1/bits/regex.h:2229
#2024 0x00005610ffe6d552 in httplib::Server::parse_request_line (this=0x7fff357a30e0, s=0x7f98b1e29e70 "GET /", 'a' <repeats 195 times>..., req=...) at ./httplib.h:4528
CoreDump is attached.
I'm somehow not able to reproduce this on my Arch, Debian and Ubuntu machine. It might be GCC version related or that alpine is using musl instead of libc. But the binary produced on alpine executed on Debian/Ubuntu/Arch crashs there too with the large request.
Thanks in advance