changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: devip: reject bad numeric ports (such as 9fs -> 9)

changeset 7160: fbb7d37047fc
parent 7159: 66132ebbe687
child 7161: 9d27035b154b
author: cinap_lenrek@felloff.net
date: Sun, 14 Apr 2019 03:22:05 +0200
files: sys/src/9/ip/devip.c
description: devip: reject bad numeric ports (such as 9fs -> 9)
     1.1--- a/sys/src/9/ip/devip.c
     1.2+++ b/sys/src/9/ip/devip.c
     1.3@@ -857,7 +857,11 @@ setladdrport(Conv* c, char* str, int ann
     1.4 		return setluniqueport(c, 0);
     1.5 	}
     1.6 
     1.7-	lport = atoi(p);
     1.8+	str = p;
     1.9+	lport = strtol(str, &p, 10);
    1.10+	if(p <= str || strchr("!", *p) == nil)
    1.11+		return "bad numeric port";
    1.12+
    1.13 	if(lport <= 0)
    1.14 		rv = setlport(c);
    1.15 	else
    1.16@@ -874,14 +878,17 @@ setraddrport(Conv* c, char* str)
    1.17 	if(p == nil)
    1.18 		return "malformed address";
    1.19 	*p++ = 0;
    1.20-	if (parseip(c->raddr, str) == -1)
    1.21+	if(parseip(c->raddr, str) == -1)
    1.22 		return Ebadip;
    1.23-	c->rport = atoi(p);
    1.24-	p = strchr(p, '!');
    1.25-	if(p){
    1.26-		if(strstr(p, "!r") != nil)
    1.27-			c->restricted = 1;
    1.28-	}
    1.29+
    1.30+	str = p;
    1.31+	c->rport = strtol(str, &p, 10);
    1.32+	if(p <= str || strchr("!", *p) == nil)
    1.33+		return "bad numeric port";
    1.34+
    1.35+	if(strstr(p, "!r") != nil)
    1.36+		c->restricted = 1;
    1.37+
    1.38 	return nil;
    1.39 }
    1.40