From 36ca0d44ee02900ed52ed143c7612341e26555e6 Mon Sep 17 00:00:00 2001 From: Julien Blanchard Date: Thu, 21 Jan 2021 09:06:32 +0000 Subject: [PATCH] Fixes: - a misordered nil check in saneurl() - an fd leak in gemini_get() - a lack of base url in gemini_get() thanks Ori! --- castor.c | 8 ++++---- url.c | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/castor.c b/castor.c index 0acc438..7ca95eb 100644 --- a/castor.c +++ b/castor.c @@ -409,7 +409,6 @@ gemini_get(Url *url) } Bflush(&body); - close(fd); h->p = hist; h->n = nil; @@ -417,14 +416,14 @@ gemini_get(Url *url) hist = h; show(c); - } + } break; case 30: - gemini_get(urlparse(nil, r->meta)); + gemini_get(urlparse(url, r->meta)); break; case 31: - gemini_get(urlparse(nil, r->meta)); + gemini_get(urlparse(url, r->meta)); break; case 40: message("Temporary failure, please try again later!"); @@ -469,6 +468,7 @@ gemini_get(Url *url) // message("Unknown status code %d!", status); // break; } + close(fd); } void diff --git a/url.c b/url.c index d1975b3..a22baea 100644 --- a/url.c +++ b/url.c @@ -223,13 +223,12 @@ mklowcase(char *s) static Url * saneurl(Url *u) { - if(strcmp(u->scheme, "mailto") == 0 && Upath(u) != nil) - return u; - if(u == nil || u->scheme == nil || u->host == nil || Upath(u) == nil){ freeurl(u); return nil; } + if(strcmp(u->scheme, "mailto") == 0 && Upath(u) != nil) + return u; if(u->port){ /* remove default ports */ switch(atoi(u->port)){ -- 2.45.2