git: 9front

Download patch

ref: 6a3167112b02cacbd30db77f5e184c9cedbb6220
parent: 3bd380117136b17d8f14f3da254ff491f257bfd5
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Oct 18 13:30:34 EDT 2025

upas/fs: strncpy -> snprint

strncpy does not do what you expect; terminate our
paths correctly in all cases.

--- a/sys/src/cmd/upas/fs/mbox.c
+++ b/sys/src/cmd/upas/fs/mbox.c
@@ -213,7 +213,7 @@
 	initheaders();
 	mb = emalloc(sizeof *mb);
 	mb->flags = flags;
-	strncpy(mb->path, path, sizeof mb->path - 1);
+	snprint(mb->path, sizeof(mb->path), "%s", path);
 	p = name;
 	if(p == nil){
 		p = strrchr(path, '/');
@@ -226,7 +226,7 @@
 			return "bad mbox name";
 		}
 	}
-	strncpy(mb->name, p, sizeof mb->name - 1);
+	snprint(mb->name, sizeof(mb->name), "%s", p);
 	mb->idxread = genericidxread;
 	mb->idxwrite = genericidxwrite;
 	mb->idxinvalid = genericidxinvalid;
@@ -1204,19 +1204,6 @@
 {
 	assert(mb->refs > 0);
 	mb->refs++;
-}
-
-static void
-mbrmidx(char *path, int flags)
-{
-	char buf[Pathlen];
-
-	snprint(buf, sizeof buf, "%s.idx", path);
-	vremove(buf);
-	if((flags & Rtrunc) == 0){
-		snprint(buf, sizeof buf, "%s.imp", path);
-		vremove(buf);
-	}
 }
 
 void
--