~julienxx/castor9

36ca0d44ee02900ed52ed143c7612341e26555e6 — Julien Blanchard 3 years ago 22f34a3
Fixes:
- a misordered nil check in saneurl()
- an fd leak in gemini_get()
- a lack of base url in gemini_get()
thanks Ori!
2 files changed, 6 insertions(+), 7 deletions(-)

M castor.c
M url.c
M castor.c => castor.c +4 -4
@@ 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

M url.c => url.c +2 -3
@@ 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)){