shithub: riscv

Download patch

ref: 83c7a727e05c7280a457bcdf5681f73ce225e0ea
parent: 810aed76a5cffd3dbbcb190d53e71eb84335a587
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Apr 13 23:22:05 EDT 2019

devip: reject bad numeric ports (such as 9fs -> 9)

--- a/sys/src/9/ip/devip.c
+++ b/sys/src/9/ip/devip.c
@@ -857,7 +857,11 @@
 		return setluniqueport(c, 0);
 	}
 
-	lport = atoi(p);
+	str = p;
+	lport = strtol(str, &p, 10);
+	if(p <= str || strchr("!", *p) == nil)
+		return "bad numeric port";
+
 	if(lport <= 0)
 		rv = setlport(c);
 	else
@@ -874,14 +878,17 @@
 	if(p == nil)
 		return "malformed address";
 	*p++ = 0;
-	if (parseip(c->raddr, str) == -1)
+	if(parseip(c->raddr, str) == -1)
 		return Ebadip;
-	c->rport = atoi(p);
-	p = strchr(p, '!');
-	if(p){
-		if(strstr(p, "!r") != nil)
-			c->restricted = 1;
-	}
+
+	str = p;
+	c->rport = strtol(str, &p, 10);
+	if(p <= str || strchr("!", *p) == nil)
+		return "bad numeric port";
+
+	if(strstr(p, "!r") != nil)
+		c->restricted = 1;
+
 	return nil;
 }