omar-polo / gmid

a Gemini server
https://gmid.omarpolo.com
ISC License
98 stars 8 forks source link

Crash when logging request from handle_handshake #1

Closed michaelforney closed 3 years ago

michaelforney commented 3 years ago

I was testing out gmid by connecting with openssl s_client, and noticed that if SNI is missing, it crashes when trying to log the request because c->iri has not been populated yet:

==837== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==837==  Access not within mapped region at address 0x0
==837==    at 0x4A75870: strlcpy (in /usr/lib/libbsd.so.0.10.0)
==837==    by 0x10AC16: log_request (gmid.c:123)
==837==    by 0x10DDBD: start_reply (server.c:274)
==837==    by 0x10D958: handle_handshake (server.c:200)
==837==    by 0x10EBB9: handle (server.c:577)
==837==    by 0x10EF7B: loop (server.c:665)
==837==    by 0x10B574: listener_main (gmid.c:332)
==837==    by 0x10B975: main (gmid.c:459)
omar-polo commented 3 years ago

Good catch! I wrote that code just yesterday and it wasn't really tested yet. It would crash also when an unknown vhost was requested (if running with a config).

Thanks!