shithub: riscv

Download patch

ref: e5894dcceaedeaf7d4f5537dd306170b1b6d4814
parent: 88a468f205af2bfdaa015a5bc33424ae0d56de08
author: kvik <[email protected]>
date: Sat Aug 1 11:27:28 EDT 2020

pre-lib9p servers: fix incorrect Tversion handling

version(5) says:

	If the server does not understand the client's version
	string, it should respond with an Rversion message (not
	Rerror) with the version string the 7 characters
	``unknown''.

Pre-lib9p file servers -- all except cwfs(4) -- do return Rerror.

lib9p(2) follows the above spec, although ignoring the next part
concerning comparison after period-stripping.  It assumes an
Fcall.version starting with "9P" is correctly formed and returns
the only supported version of the protocol, which seems alright.

This patch brings pre-lib9p servers in accordance with the spec.

--- a/sys/src/cmd/9660srv/main.c
+++ b/sys/src/cmd/9660srv/main.c
@@ -254,6 +254,8 @@
 	else
 		rep->msize = req->msize;
 	rep->version = "9P2000";
+	if(strncmp(req->version, "9P", 2) != 0)
+		rep->version = "unknown";
 }
 
 void
--- a/sys/src/cmd/acme/fsys.c
+++ b/sys/src/cmd/acme/fsys.c
@@ -325,9 +325,9 @@
 		return respond(x, &t, "version: message size too small");
 	messagesize = x->msize;
 	t.msize = messagesize;
-	if(strncmp(x->version, "9P2000", 6) != 0)
-		return respond(x, &t, "unrecognized 9P version");
 	t.version = "9P2000";
+	if(strncmp(x->version, "9P", 2) != 0)
+		t.version = "unknown";
 	return respond(x, &t, nil);
 }
 
--- a/sys/src/cmd/auth/keyfs.c
+++ b/sys/src/cmd/auth/keyfs.c
@@ -258,9 +258,9 @@
 	else
 		thdr.msize = rhdr.msize;
 	messagesize = thdr.msize;
-	if(strncmp(rhdr.version, "9P2000", 6) != 0)
-		return "bad 9P version";
 	thdr.version = "9P2000";
+	if(strncmp(rhdr.version, "9P", 2) != 0)
+		thdr.version = "unknown";
 	return 0;
 }
 
--- a/sys/src/cmd/aux/9pcon.c
+++ b/sys/src/cmd/aux/9pcon.c
@@ -57,7 +57,7 @@
 	}
 	if(n == 0)
 		print("server eof\n");
-	else
+	else if(n == -1)
 		print("read9pmsg from server: %r\n");
 }
 
--- a/sys/src/cmd/aux/consolefs.c
+++ b/sys/src/cmd/aux/consolefs.c
@@ -763,12 +763,10 @@
 	if(messagesize > 8192+IOHDRSZ)
 		messagesize = 8192+IOHDRSZ;
 	r->f.msize = messagesize;
-	if(strncmp(r->f.version, "9P2000", 6) != 0){
-		fsreply(fs, r, "unrecognized 9P version");
-		return;
-	}
-	r->f.version = "9P2000";
-
+	if(strncmp(r->f.version, "9P", 2) != 0)
+		r->f.version = "unknown";
+	else
+		r->f.version = "9P2000";
 	fsreply(fs, r, nil);
 }
 
--- a/sys/src/cmd/aux/depend.c
+++ b/sys/src/cmd/aux/depend.c
@@ -472,7 +472,10 @@
 	if(messagesize > r->f.msize)
 		messagesize = r->f.msize;
 	r->f.msize = messagesize;
-	r->f.version = "9P2000";
+	if(strncmp(r->f.version, "9P", 2) != 0)
+		r->f.version = "unknown";
+	else
+		r->f.version = "9P2000";
 	fsreply(fs, r, nil);
 }
 
--- a/sys/src/cmd/aux/searchfs.c
+++ b/sys/src/cmd/aux/searchfs.c
@@ -687,9 +687,10 @@
 	if(rpc->msize > messagesize)
 		rpc->msize = messagesize;
 	messagesize = rpc->msize;
-	if(strncmp(rpc->version, "9P2000", 6) != 0)
-		return "unrecognized 9P version";
-	rpc->version = "9P2000";
+	if(strncmp(rpc->version, "9P", 2) != 0)
+		rpc->version = "unknown";
+	else
+		rpc->version = "9P2000";
 	return nil;
 }
 
--- a/sys/src/cmd/bzfs/oramfs.c
+++ b/sys/src/cmd/bzfs/oramfs.c
@@ -116,7 +116,6 @@
 char	Eisopen[] = 	"file already open for I/O";
 char	Excl[] = 	"exclusive use file already open";
 char	Ename[] = 	"illegal name";
-char	Eversion[] =	"unknown 9P version";
 
 int debug;
 
@@ -228,9 +227,9 @@
 	else
 		rhdr.msize = thdr.msize;
 	messagesize = rhdr.msize;
-	if(strncmp(thdr.version, "9P2000", 6) != 0)
-		return Eversion;
 	rhdr.version = "9P2000";
+	if(strncmp(thdr.version, "9P", 2) != 0)
+		rhdr.version = "unknown";
 	return 0;
 }
 
--- a/sys/src/cmd/dossrv/dosfs.c
+++ b/sys/src/cmd/dossrv/dosfs.c
@@ -15,6 +15,8 @@
 	else
 		rep->msize = req->msize;
 	rep->version = "9P2000";
+	if(strncmp(req->version, "9P", 2) != 0)
+		rep->version = "unknown";
 }
 
 void
--- a/sys/src/cmd/exportfs/exportsrv.c
+++ b/sys/src/cmd/exportfs/exportsrv.c
@@ -15,7 +15,6 @@
 char Emip[] = "Mount in progress";
 char Enopsmt[] = "Out of pseudo mount points";
 char Enomem[] = "No memory";
-char Eversion[] = "Bad 9P2000 version";
 char Ereadonly[] = "File system read only";
 char Enoprocs[] = "Out of processes";
 
@@ -35,13 +34,10 @@
 	if(t->work.msize > messagesize)
 		t->work.msize = messagesize;
 	messagesize = t->work.msize;
-	if(strncmp(t->work.version, "9P2000", 6) != 0){
-		reply(&t->work, &rhdr, Eversion);
-		putsbuf(t);
-		return;
-	}
-	rhdr.version = "9P2000";
 	rhdr.msize = t->work.msize;
+	rhdr.version = "9P2000";
+	if(strncmp(t->work.version, "9P", 2) != 0)
+		rhdr.version = "unknown";
 	reply(&t->work, &rhdr, 0);
 	putsbuf(t);
 }
--- a/sys/src/cmd/ip/ftpfs/ftpfs.c
+++ b/sys/src/cmd/ip/ftpfs/ftpfs.c
@@ -314,9 +314,9 @@
 		rhdr.msize = thdr.msize;
 	messagesize = rhdr.msize;
 
-	if(strncmp(thdr.version, "9P2000", 6) != 0)
-		return "unknown 9P version";
 	rhdr.version = "9P2000";
+	if(strncmp(thdr.version, "9P", 2) != 0)
+		rhdr.version = "unknown";
 	return nil;
 }
 
--- a/sys/src/cmd/lnfs.c
+++ b/sys/src/cmd/lnfs.c
@@ -90,7 +90,6 @@
 char	Eisopen[] = 	"file already open for I/O";
 char	Excl[] = 	"exclusive use file already open";
 char	Ename[] = 	"illegal name";
-char	Eversion[] =	"unknown 9P version";
 
 void
 usage(void)
@@ -195,9 +194,9 @@
 	else
 		rhdr.msize = thdr.msize;
 	messagesize = rhdr.msize;
-	if(strncmp(thdr.version, "9P2000", 6) != 0)
-		return Eversion;
 	rhdr.version = "9P2000";
+	if(strncmp(thdr.version, "9P", 2) != 0)
+		rhdr.version = "unknown";
 	return nil;
 }
 
--- a/sys/src/cmd/ndb/cs.c
+++ b/sys/src/cmd/ndb/cs.c
@@ -510,12 +510,10 @@
 		job->reply.msize = IOHDRSZ + Maxfdata;
 	else
 		job->reply.msize = job->request.msize;
-	if(strncmp(job->request.version, "9P2000", 6) != 0)
-		sendmsg(job, "unknown 9P version");
-	else{
-		job->reply.version = "9P2000";
-		sendmsg(job, nil);
-	}
+	job->reply.version = "9P2000";
+	if(strncmp(job->request.version, "9P", 2) != 0)
+		job->reply.version = "unknown";
+	sendmsg(job, nil);
 }
 
 void
--- a/sys/src/cmd/ndb/dns.c
+++ b/sys/src/cmd/ndb/dns.c
@@ -485,12 +485,10 @@
 		job->reply.msize = IOHDRSZ + Maxfdata;
 	else
 		job->reply.msize = job->request.msize;
-	if(strncmp(job->request.version, "9P2000", 6) != 0)
-		sendmsg(job, "unknown 9P version");
-	else{
-		job->reply.version = "9P2000";
-		sendmsg(job, 0);
-	}
+	job->reply.version = "9P2000";
+	if(strncmp(job->request.version, "9P", 2) != 0)
+		job->reply.version = "unknown";
+	sendmsg(job, nil);
 }
 
 void
--- a/sys/src/cmd/paqfs/paqfs.c
+++ b/sys/src/cmd/paqfs/paqfs.c
@@ -135,7 +135,6 @@
 char	Ename[] = 	"illegal name";
 char	Erdonly[] = 	"read only file system";
 char	Ebadblock[] = 	"bad block";
-char	Eversion[] = 	"bad version of P9";
 char	Edirtoobig[] = 	"directory entry too big";
 
 int debug;
@@ -270,9 +269,9 @@
 		thdr.msize = mesgsize;
 	else
 		thdr.msize = rhdr.msize;
-	if(strcmp(rhdr.version, "9P2000") != 0)
-		return Eversion;
 	thdr.version = "9P2000";
+	if(strncmp(rhdr.version, "9P", 2) != 0)
+		thdr.version = "unknown";
 	return 0;
 }
 
--- a/sys/src/cmd/plumb/fsys.c
+++ b/sys/src/cmd/plumb/fsys.c
@@ -563,11 +563,10 @@
 	if(t->msize < messagesize)
 		messagesize = t->msize;
 	t->msize = messagesize;
-	if(strncmp(t->version, "9P2000", 6) != 0){
-		fsysrespond(t, buf, "unrecognized 9P version");
-		return t;
-	}
-	t->version = "9P2000";
+	if(strncmp(t->version, "9P", 2) != 0)
+		t->version = "unknown";
+	else
+		t->version = "9P2000";
 	fsysrespond(t, buf, nil);
 	return t;
 }
--- a/sys/src/cmd/ratfs/proto.c
+++ b/sys/src/cmd/ratfs/proto.c
@@ -131,9 +131,16 @@
 static void
 rversion(Fcall *f)
 {
-	f->version = "9P2000";
+	if(f->msize < 256){
+		reply(f, "version: message size too small");
+		return;
+	}
 	if(f->msize > MAXRPC)
 		f->msize = MAXRPC;
+	if(strncmp(f->version, "9P", 2) != 0)
+		f->version = "unknown";
+	else
+		f->version = "9P2000";
 	reply(f, 0);
 }
 
--- a/sys/src/cmd/rio/fsys.c
+++ b/sys/src/cmd/rio/fsys.c
@@ -294,9 +294,9 @@
 		return filsysrespond(x->fs, x, &t, "version: message size too small");
 	messagesize = x->msize;
 	t.msize = messagesize;
-	if(strncmp(x->version, "9P2000", 6) != 0)
-		return filsysrespond(x->fs, x, &t, "unrecognized 9P version");
 	t.version = "9P2000";
+	if(strncmp(x->version, "9P", 2) != 0)
+		t.version = "unknown";
 	return filsysrespond(fs, x, &t, nil);
 }
 
--- a/sys/src/cmd/tapefs/fs.c
+++ b/sys/src/cmd/tapefs/fs.c
@@ -160,9 +160,9 @@
 	else
 		messagesize = rhdr.msize;
 	thdr.msize = messagesize;
-	if(strncmp(rhdr.version, "9P2000", 6) != 0)
-		return "unrecognized 9P version";
 	thdr.version = "9P2000";
+	if(strncmp(rhdr.version, "9P", 2) != 0)
+		thdr.version = "unknown";
 
 	for(f = fids; f; f = f->next)
 		if(f->busy)
--- a/sys/src/cmd/telco/telco.c
+++ b/sys/src/cmd/telco/telco.c
@@ -519,9 +519,9 @@
 	if(messagesize > sizeof mdata)
 		messagesize = sizeof mdata;
 	rhdr.msize = messagesize;
-	if(strncmp(thdr.version, "9P2000", 6) != 0)
-		return "unrecognized 9P version";
 	rhdr.version = "9P2000";
+	if(strncmp(thdr.version, "9P", 2) != 0)
+		rhdr.version = "unknown";
 	return 0;
 }
 
--- a/sys/src/cmd/upas/fs/fs.c
+++ b/sys/src/cmd/upas/fs/fs.c
@@ -726,10 +726,10 @@
 	if(thdr.msize < messagesize)
 		messagesize = thdr.msize;
 	rhdr.msize = messagesize;
-	if(strncmp(thdr.version, "9P2000", 6) != 0)
-		return "unknown 9P version";
-	else
-		rhdr.version = "9P2000";
+	rhdr.version = "9P2000";
+	if(strncmp(thdr.version, "9P", 2) != 0)
+		rhdr.version = "unknown";
+		
 	for(f = fids; f; f = f->next)
 		if(f->busy)
 			rclunk(f);
--- a/sys/src/cmd/vac/vacfs.c
+++ b/sys/src/cmd/vac/vacfs.c
@@ -255,13 +255,13 @@
 	if(messagesize > sizeof mdata)
 		messagesize = sizeof mdata;
 	thdr.msize = messagesize;
-	if(strncmp(rhdr.version, "9P2000", 6) != 0)
-		return vtstrdup("unrecognized 9P version");
-	thdr.version = "9P2000";
+	if(strncmp(rhdr.version, "9P", 2) != 0)
+		thdr.version = "unknown";
 	if(strncmp(rhdr.version, "9P2000.u", 8) == 0){
 		dotu = 1;
 		thdr.version = "9P2000.u";
-	}
+	}else
+		thdr.version = "9P2000";
 	return nil;
 }