shithub: gefs

Download patch

ref: d60c4cb716bc586ef3641d77da53bb7af0fee87f
parent: 1570a56a00b7e19f249ed4b865b438c7ba00934d
author: glenda <glenda@9front.local>
date: Fri Dec 17 19:30:42 EST 2021

fs: more constants, safer sizing.

--- a/dat.h
+++ b/dat.h
@@ -53,6 +53,7 @@
 	Offksz	= 17,			/* type, qid, off */
 	Snapsz	= 9,			/* tag, snapid */
 	Treesz	= 4+Ptrsz+Ptrsz,	/* height, root, deadlist */
+	Wstatmax = 1+4+8+8+8,		/* op, mode, len, mtime, atime */
 	Kvmax	= Keymax + Inlmax,	/* Key and value */
 	Kpmax	= Keymax + Ptrsz,	/* Key and pointer */
 	
--- a/fs.c
+++ b/fs.c
@@ -174,7 +174,7 @@
 static int
 readb(Fid *f, char *d, vlong o, vlong n, int sz)
 {
-	char *e, buf[17], kvbuf[17+32];
+	char *e, buf[Offksz], kvbuf[Offksz+Ptrsz];
 	vlong fb, fo;
 	Bptr bp;
 	Blk *b;
@@ -583,7 +583,7 @@
 	for(i = 0; i < m->nwname; i++){
 		up = prev;
 		p = kbuf;
-		e = p + sizeof(kbuf);
+		e = kbuf + sizeof(kbuf);
 		p = pack8(&err, p, e, Kent);
 		p = pack64(&err, p, e, up);
 		p = packstr(&err, p, e, m->wname[i]);
@@ -1161,7 +1161,7 @@
 void
 fswrite(Fmsg *m)
 {
-	char sbuf[8], offbuf[4][Ptrsz+Offksz];
+	char sbuf[Wstatmax], offbuf[4][Offksz+Ptrsz];
 	char *p, *e;
 	vlong n, o, c;
 	Msg kv[4];
--- a/sync.c
+++ b/sync.c
@@ -64,6 +64,7 @@
 	if((e = btlookup(&fs->snap, &k, &kv, buf, sizeof(buf))) != nil)
 		return e;
 	p = kv.v;
+	memset(t, 0, sizeof(*t));
 	t->ht = GBIT32(p);		p += 4;
 	t->bp.addr = GBIT64(p);		p += 8;
 	t->bp.hash = GBIT64(p);		p += 8;