Commit Briefs

Omar Polo

rework net_read() a bit

- don't stop after parsing the header maybe there's some page data in the buffer, let's try to forward it immediately too. - use a local buffer plus bufferevent_read()



Omar Polo

net: don't need a uri, just host and port fields

While here, make 'em dinamically allocated.



Omar Polo

re-group the handling of imsgs

while here also do more validation in IMSG_GET_RAW and add a missing NULL check in the return type of req_by_id in the IMSG_CERT_STATUS.



Omar Polo

get rid of some ifdefs

just declare the same function in the two branches of #if HAVE_ASR_RUN to avoid further #ifs


Omar Polo

avoid unnecessary else



Omar Polo

work around macos lack of SOCK_CLOEXEC / SOCK_NONBLOCK

rework mark_nonblock so it sets the cloexec flag too and use it in control.c to avoid these flags. (which are expected to become available on a future revision of POSIX and are already widely available.) It's not an issue for telescope to do the socket/accept + fcntl dance because there aren't threads that can fork(2) (there are no threads at all!) reported by @sikmir at github https://github.com/omar-polo/telescope/commit/59ef79dd19611c7846b00427e6f2267c748ae290#r74498414


Omar Polo

gemini_parse_reply: return code and don't close connection

clang static analyzer found a possible use after free: if the code is not 2X in gemini_parse_reply we call close_conn. Then, in net_read we set req->done_header, but req may have been free'd! Actually, this is almost impossible to trigger. close_conn never ends up calling free(req) on its first try, because tls_close takes a while and is rescheduled by libevent. (The check req->ctx != NULL in close_conn is always true if it's a gemini request.) Nevertheless, it's clear to move close_conn out of gemini_parse_reply and simply return the response code: it feels wrong that a "parsing function" takes logic decisions.



Omar Polo

move util.c declarations in utils.h

it's not spelled `util.h' because otherwise it'd get included instead of /usr/include/util.h


Omar Polo

re-create the tls_config for each request

this is just to simplify the future additions of client certificates.


Omar Polo

handle empty replies (i.e. no header)

thanks mansfield for breaking your server so I notice this error