"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
gotwebd: fix null-deref and ENOMEM question
To:
gameoftrees@openbsd.org
Date:
Tue, 23 Aug 2022 10:39:26 +0200

Download raw body.

Thread
i had another gotwebd crash.  This one is pretty simple to fix, in
gotweb_process_request if gotweb_init_querystring fails c->t-qs is
NULL and at the end of the function we might crash.

diff /home/op/w/got
commit - 4d648b92ac1ac5f952a42f29052c56e8d32547a3
path + /home/op/w/got
blob - 072126ddb17614b1c833d48856c433c128ab891c
file + gotwebd/gotweb.c
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -292,7 +292,7 @@ err:
 	if (html && fcgi_printf(c, "</div>\n") == -1)
 		return;
 done:
-	if (c->t->repo != NULL && qs->action != INDEX)
+	if (c->t->repo != NULL && qs && qs->action != INDEX)
 		got_repo_close(c->t->repo);
 	if (html && srv != NULL)
 		gotweb_render_footer(c);

easy to fix.

but now the question, i had these logs:

------8<--------
gotweb_process_request: malloc: Cannot allocate memory
gotweb_process_request: malloc: Cannot allocate memory
gotweb_process_request: malloc: Cannot allocate memory
gotweb_process_request: malloc: Cannot allocate memory
gotweb_process_request: malloc: Cannot allocate memory
gotweb_process_request: malloc: Cannot allocate memory
send_response: write failure: Bad file descriptor
cannot allocate env_entry->val: Cannot allocate memory
cannot allocate env_entry->val: Cannot allocate memory
cannot allocate env_entry->val: Cannot allocate memory
fcgi_printf: asprintf: Cannot allocate memory
gotweb_process_request: scandir: /got/public: Cannot allocate memory
cannot allocate env_entry->val: Cannot allocate memory
fcgi_printf: asprintf: Cannot allocate memory
gotweb_process_request: scandir: /got/public: Cannot allocate memory
cannot allocate env_entry->val
Cannot allocate memory
cannot allocate env_entry->val: Cannot allocate memory
gotweb_process_request: %s: strdup: gotweb_parse_querystring: Cannot allocate memory
fcgi_printf: asprintf: Cannot allocate memory
cannot malloc env_entry: Cannot allocate memory
gotweb_process_request: %s: calloc: gotweb_init_querystring: Cannot allocate memory
fcgi_printf: asprintf: Cannot allocate memory
cannot malloc env_entry: Cannot allocate memory
fcgi_printf: asprintf: Cannot allocate memory
gotweb_process_request: scandir: /got/public: Cannot allocate memory
cannot allocate env_entry->val: Cannot allocate memory
fcgi_printf: asprintf: Cannot allocate memory
gotweb_process_request: scandir: /got/public: Cannot allocate memory
fcgi_printf: asprintf: Cannot allocate memory
cannot malloc env_entry: Cannot allocate memory
gotweb_process_request: %s: strdup: gotweb_init_querystring: Cannot allocate memory
cannot allocate env_entry->val: Cannot allocate memory
gotweb_process_request: %s: strdup: gotweb_parse_querystring: Cannot allocate memory
cannot allocate env_entry->val
Cannot allocate memory
gotweb_process_request: %s: calloc: gotweb_init_transport: Cannot allocate memory
------>8--------

that's a lot of ENOMEM!

(the logs don't have a date attached to them because i'm running
gotwebd -dv so the logs don't go thru syslog.)

well, on the bright side it's a nice test for the error path.

i don't have a monitoring thing set up so i don't know the state of
the system when this happened, but other serivces (httpd, slowcgi,
gmid, prosody, ...) are all fine and don't see any scary lines in
/var/log/messages