shithub: riscv

Download patch

ref: ffe4844da89587a3a5cb806abd01d61c1b4b4aa4
parent: 76e0968e35f03ec848093072458e3d15bee2f372
author: cinap_lenrek <[email protected]>
date: Sat Sep 26 07:44:29 EDT 2015

cwfs: various cleanups

- consistently refer to Dentry.name length with NAMELEN
- make sure whoname is null terminated
- remove useless nil check for whoname

--- a/sys/src/cmd/cwfs/9p2.c
+++ b/sys/src/cmd/cwfs/9p2.c
@@ -348,7 +348,7 @@
 
 	r->qid = file->qid;
 
-	strncpy(chan->whoname, f->uname, sizeof(chan->whoname));
+	snprint(chan->whoname, sizeof(chan->whoname), "%s", f->uname);
 	chan->whotime = time(nil);
 out:
 	if(p != nil)
@@ -913,7 +913,7 @@
 		goto phase;
 	}
 
-	strncpy(d1->name, f->name, sizeof(d1->name));
+	strncpy(d1->name, f->name, NAMELEN);
 	if(chan == cons.chan){
 		d1->uid = cons.uid;
 		d1->gid = cons.gid;
@@ -1014,7 +1014,6 @@
 	}
 	iounit = chan->msize-IOHDRSZ;
 	if(count < 0 || count > iounit){
-fprint(2, "fs_read %d %d\n", count, iounit);
 		error = Ecount;
 		goto out;
 	}
@@ -1786,7 +1785,7 @@
 		}
 		d->size = dir.length;
 		if(dir.name != d->name)
-			strncpy(d->name, dir.name, sizeof(d->name));
+			strncpy(d->name, dir.name, NAMELEN);
 		d->uid = uid;
 		d->gid = gid;
 		d->muid = muid;
--- a/sys/src/cmd/cwfs/con.c
+++ b/sys/src/cmd/cwfs/con.c
@@ -14,7 +14,7 @@
 {
 	int i;
 
-	strncpy(cons.chan->whochan, "console", sizeof(cons.chan->whochan));
+	snprint(cons.chan->whochan, sizeof(cons.chan->whochan), "console");
 	installcmds();
 	con_session();
 	cmd_exec("cfs");
@@ -312,8 +312,7 @@
 				continue;
 			}
 		}
-		print("%3d: %10s %24s", cp->chan,
-			cp->whoname? cp->whoname: "<nowhoname>", cp->whochan);
+		print("%3d: %10s %24s", cp->chan, cp->whoname, cp->whochan);
 		if(cp->whoprint)
 			cp->whoprint(cp);
 		print("\n");
--- a/sys/src/cmd/cwfs/sub.c
+++ b/sys/src/cmd/cwfs/sub.c
@@ -46,7 +46,7 @@
 		chans = cp;
 		cp->chan = cons.chano;
 		cons.chano++;
-		strncpy(cp->whoname, "<none>", sizeof cp->whoname);
+		snprint(cp->whoname, sizeof(cp->whoname), "<none>");
 		wlock(&cp->reflock);
 		wunlock(&cp->reflock);
 		rlock(&cp->reflock);