shithub: castor9

Download patch

ref: 36ca0d44ee02900ed52ed143c7612341e26555e6
parent: 22f34a315b71fdeb2ac90b79f134e11b3052f07a
author: Julien Blanchard <[email protected]>
date: Thu Jan 21 04:06:32 EST 2021

Fixes:
- a misordered nil check in saneurl()
- an fd leak in gemini_get()
- a lack of base url in gemini_get()
thanks Ori!

--- a/castor.c
+++ b/castor.c
@@ -409,7 +409,6 @@
 			}
 
 			Bflush(&body);
-			close(fd);
 
 			h->p = hist;
 			h->n = nil;
@@ -417,14 +416,14 @@
 			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 @@
 	//	message("Unknown status code %d!", status);
 	//	break;
 	}
+	close(fd);
 }
 
 void
--- a/url.c
+++ b/url.c
@@ -223,13 +223,12 @@
 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)){