shithub: 9pro

Download patch

ref: d79335d57a7f6f608e8caf800b74155a299a550c
parent: fdd8f1021298e7080e943a4bdbfc4a84952d9c0b
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Fri Apr 30 10:17:30 EDT 2021

Squashed 'c9/' changes from 96d3672..3196726

3196726 r32, r64: no UB plz (thanks kvik)
0c2839a %u → %ud (thanks kvik)
e0eae33 add C9excl

git-subtree-dir: c9
git-subtree-split: 3196726bc5d4d308995fbfb00a2da55cd1118a14

--- a/c9/c9.c
+++ b/c9/c9.c
@@ -83,19 +83,24 @@
 r16(uint8_t **p)
 {
 	*p += 2;
-	return (uint16_t)(*p)[-2]<<0 | (uint16_t)(*p)[-1]<<8;
+	return (*p)[-2]<<0 | (*p)[-1]<<8;
 }
 
 static uint32_t
 r32(uint8_t **p)
 {
-	return r16(p) | (uint32_t)r16(p)<<16;
+	*p += 4;
+	return (*p)[-4]<<0 | (*p)[-3]<<8 | (*p)[-2]<<16 | (*p)[-1]<<24;
 }
 
 static uint64_t
 r64(uint8_t **p)
 {
-	return r32(p) | (uint64_t)r32(p)<<32;
+	uint64_t v;
+
+	v = r32(p);
+	v |= (uint64_t)r32(p)<<32;
+	return v;
 }
 
 #ifndef C9_NO_CLIENT
@@ -143,11 +148,11 @@
 	if(tag != 0xffff){
 		uint32_t d = tag / C9tagsbits, m = tag % C9tagsbits;
 		if(tag >= C9maxtags){
-			c->error("freetag: invalid tag %u", (uint32_t)tag);
+			c->error("freetag: invalid tag %ud", (uint32_t)tag);
 			return -1;
 		}
 		if((c->tags[d] & 1<<m) != 0){
-			c->error("freetag: double free for tag %u", (uint32_t)tag);
+			c->error("freetag: double free for tag %ud", (uint32_t)tag);
 			return -1;
 		}
 		if(c->lowfreetag > tag)
@@ -163,12 +168,12 @@
 	uint8_t *p = NULL;
 
 	if(size > c->msize-4-1-2){
-		c->error("T: invalid size %u", size);
+		c->error("T: invalid size %ud", size);
 		*err = C9Esize;
 	}else if((*err = newtag(c, type, tag)) == 0){
 		size += 4+1+2;
 		if((p = c->begin(c, size)) == NULL){
-			c->error("T: no buffer for %u bytes", size);
+			c->error("T: no buffer for %ud bytes", size);
 			freetag(c, *tag);
 			*err = C9Ebuf;
 		}else{
@@ -188,7 +193,7 @@
 	C9error err;
 
 	if(msize < C9minmsize){
-		c->error("c9version: msize too small: %u", msize);
+		c->error("c9version: msize too small: %ud", msize);
 		return C9Einit;
 	}
 	memset(c->tags, 0xff, sizeof(c->tags));
@@ -212,7 +217,7 @@
 	C9error err;
 
 	if(ulen > C9maxstr || alen > C9maxstr){
-		c->error("c9auth: string too long: %u chars", ulen > alen ? ulen : alen);
+		c->error("c9auth: string too long: %ud chars", ulen > alen ? ulen : alen);
 		return C9Estr;
 	}
 	if((b = T(c, 4+2+ulen+2+alen, Tauth, tag, &err)) != NULL){
@@ -253,7 +258,7 @@
 	C9error err;
 
 	if(ulen > C9maxstr || alen > C9maxstr){
-		c->error("c9attach: string too long: %u chars", ulen > alen ? ulen : alen);
+		c->error("c9attach: string too long: %ud chars", ulen > alen ? ulen : alen);
 		return C9Estr;
 	}
 	if((b = T(c, 4+4+2+ulen+2+alen, Tattach, tag, &err)) != NULL){
@@ -277,13 +282,13 @@
 	for(sz = i = 0; i < (int)sizeof(len)/sizeof(len[0]) && path[i] != NULL; i++){
 		len[i] = safestrlen(path[i]);
 		if(len[i] == 0 || len[i] > C9maxstr){
-			c->error("c9walk: invalid path element: %u chars", len[i]);
+			c->error("c9walk: invalid path element: %ud chars", len[i]);
 			return C9Epath;
 		}
 		sz += 2 + len[i];
 	}
 	if(path[i] != NULL){
-		c->error("c9walk: invalid elements !(0 <= %u <= %u)", i, C9maxpathel);
+		c->error("c9walk: invalid elements !(0 <= %ud <= %ud)", i, C9maxpathel);
 		return C9Epath;
 	}
 
@@ -320,7 +325,7 @@
 	C9error err;
 
 	if(nlen == 0 || nlen > C9maxstr){
-		c->error("c9create: invalid name: %u chars", nlen);
+		c->error("c9create: invalid name: %ud chars", nlen);
 		return C9Epath;
 	}
 	if((b = T(c, 4+2+nlen+4+1, Tcreate, tag, &err)) != NULL){
@@ -418,11 +423,11 @@
 	C9error err;
 
 	if(nlen == 0 || nlen > C9maxstr){
-		c->error("c9wstat: invalid name: %u chars", nlen);
+		c->error("c9wstat: invalid name: %ud chars", nlen);
 		return C9Epath;
 	}
 	if(ulen > C9maxstr || glen > C9maxstr){
-		c->error("c9wstat: string too long: %u chars", ulen > glen ? ulen : glen);
+		c->error("c9wstat: string too long: %ud chars", ulen > glen ? ulen : glen);
 		return C9Estr;
 	}
 	if((b = T(c, 4+2+2+statsz, Twstat, tag, &err)) != NULL){
@@ -461,7 +466,7 @@
 
 	sz = r32(&b);
 	if(sz < 7 || sz > c->msize){
-		c->error("c9proc: invalid packet size !(7 <= %u <= %u)", sz, c->msize);
+		c->error("c9proc: invalid packet size !(7 <= %ud <= %ud)", sz, c->msize);
 		return C9Epkt;
 	}
 	sz -= 4;
@@ -476,7 +481,7 @@
 	r.tag = r16(&b);
 	if(r.type != Rversion){
 		if(r.tag >= C9maxtags){
-			c->error("c9proc: invalid tag %u", (uint32_t)r.tag);
+			c->error("c9proc: invalid tag %ud", (uint32_t)r.tag);
 			return C9Epkt;
 		}
 		if(freetag(c, r.tag) != 0)
@@ -505,7 +510,7 @@
 		if(sz < 2 || (cnt = r16(&b))*13 > sz-2)
 			goto error;
 		if(cnt > C9maxpathel){
-			c->error("c9proc: Rwalk !(%u <= %u)", cnt, C9maxpathel);
+			c->error("c9proc: Rwalk !(%ud <= %ud)", cnt, C9maxpathel);
 			return C9Epath;
 		}
 		for(i = 0; i < cnt; i++){
@@ -588,7 +593,7 @@
 	}
 	return 0;
 error:
-	c->error("c9proc: invalid packet type %u", r.type);
+	c->error("c9proc: invalid packet type %ud", r.type);
 	return C9Epkt;
 }
 
@@ -628,7 +633,7 @@
 	*t += sz;
 	return 0;
 error:
-	c->error("c9parsedir: invalid size: size=%u sz=%u", *size, sz);
+	c->error("c9parsedir: invalid size: size=%ud sz=%ud", *size, sz);
 	return C9Epkt;
 }
 
@@ -640,12 +645,12 @@
 	uint8_t *p = NULL;
 
 	if(size > c->msize-4-1-2){
-		c->error("R: invalid size %u", size);
+		c->error("R: invalid size %ud", size);
 		*err = C9Esize;
 	}else{
 		size += 4+1+2;
 		if((p = c->begin(c, size)) == NULL){
-			c->error("R: no buffer for %u bytes", size);
+			c->error("R: no buffer for %ud bytes", size);
 			*err = C9Ebuf;
 		}else{
 			*err = 0;
@@ -694,7 +699,7 @@
 	C9error err;
 
 	if(len > C9maxstr){
-		c->error("s9error: invalid ename: %u chars", len);
+		c->error("s9error: invalid ename: %ud chars", len);
 		return C9Estr;
 	}
 	if((b = R(c, 2+len, Rerror, tag, &err)) != NULL){
@@ -738,7 +743,7 @@
 
 	for(n = 0; n < C9maxpathel && qids[n] != NULL; n++);
 	if(n > C9maxpathel){
-		c->error("s9walk: invalid elements !(0 <= %u <= %u)", n, C9maxpathel);
+		c->error("s9walk: invalid elements !(0 <= %ud <= %ud)", n, C9maxpathel);
 		return C9Epath;
 	}
 
@@ -834,13 +839,13 @@
 		mulen = safestrlen(s->muid);
 
 		if(nlen == 0 || nlen > C9maxstr){
-			c->error("s9readdir: invalid name: %u chars", nlen);
+			c->error("s9readdir: invalid name: %ud chars", nlen);
 			return C9Epath;
 		}
 		if(ulen > C9maxstr || glen > C9maxstr || mulen > C9maxstr){
 			ulen = ulen > glen ? ulen : glen;
 			ulen = ulen > mulen ? ulen : mulen;
-			c->error("s9readdir: string too long: %u chars", ulen);
+			c->error("s9readdir: string too long: %ud chars", ulen);
 			return C9Estr;
 		}
 
@@ -911,13 +916,13 @@
 	C9error err;
 
 	if(nlen == 0 || nlen > C9maxstr){
-		c->error("s9stat: invalid name: %u chars", nlen);
+		c->error("s9stat: invalid name: %ud chars", nlen);
 		return C9Epath;
 	}
 	if(ulen > C9maxstr || glen > C9maxstr || mulen > C9maxstr){
 		ulen = ulen > glen ? ulen : glen;
 		ulen = ulen > mulen ? ulen : mulen;
-		c->error("s9stat: string too long: %u chars", ulen);
+		c->error("s9stat: string too long: %ud chars", ulen);
 		return C9Estr;
 	}
 
@@ -970,7 +975,7 @@
 
 	sz = r32(&b);
 	if(sz < 7 || sz > c->msize){
-		c->error("s9proc: invalid packet size !(7 <= %u <= %u)", sz, c->msize);
+		c->error("s9proc: invalid packet size !(7 <= %ud <= %ud)", sz, c->msize);
 		return C9Epkt;
 	}
 	sz -= 4;
@@ -986,7 +991,7 @@
 	sz -= 3;
 
 	if((c->svflags & Svver) == 0 && t.type != Tversion){
-		c->error("s9proc: expected Tversion, got %u", t.type);
+		c->error("s9proc: expected Tversion, got %ud", t.type);
 		return C9Epkt;
 	}
 
@@ -1030,7 +1035,7 @@
 		t.fid = r32(&b);
 		t.walk.newfid = r32(&b);
 		if((n = r16(&b)) > 16){
-			c->error("s9proc: Twalk !(%u <= 16)", n);
+			c->error("s9proc: Twalk !(%ud <= 16)", n);
 			return C9Epath;
 		}
 		sz -= 4+4+2;
@@ -1039,7 +1044,7 @@
 				if(sz < 2 || (cnt = r16(&b)) > sz-2)
 					goto error;
 				if(cnt < 1){
-					c->error("s9proc: Twalk invalid element [%u]", i);
+					c->error("s9proc: Twalk invalid element [%ud]", i);
 					return C9Epath;
 				}
 				b[-2] = 0;
@@ -1164,7 +1169,7 @@
 	}
 	return 0;
 error:
-	c->error("s9proc: invalid packet (type=%u)", t.type);
+	c->error("s9proc: invalid packet (type=%ud)", t.type);
 	return C9Epkt;
 }
 
--- a/c9/c9.h
+++ b/c9/c9.h
@@ -32,6 +32,7 @@
 	C9exec = 3,
 	C9trunc = 0x10,
 	C9rclose = 0x40,
+	C9excl = 0x1000,
 }C9mode;
 
 typedef enum