ref: 563cf85e63350141c763744358584ac0edfb9e2c
parent: dcd6920bda655b7c1bf8245db3a60589afe848ab
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Nov 2 11:29:16 EST 2025
lib9p: use Emsize for "message size too small" Use sizeD2M() instead of calling convD2M() twice. Use common Emsize = "message size too small" error string for Tversion and Rstat.
--- a/sys/src/lib9p/srv.c
+++ b/sys/src/lib9p/srv.c
@@ -23,6 +23,7 @@
static char Eunknownfid[] = "unknown fid";
static char Ebaddir[] = "bad directory in wstat";
static char Ewalknodir[] = "walk in non-directory";
+static char Emsize[] = "message size too small";
static void
setfcallerror(Fcall *f, char *err)
@@ -175,7 +176,7 @@
}
r->ofcall.version = "9P2000";
if(r->ifcall.msize < 256){- respond(r, "version: message size too small");
+ respond(r, Emsize);
return;
}
if(r->ifcall.msize < 1024*1024)
@@ -660,31 +661,24 @@
else
respond(r, Enostat);
}
+
static void
rstat(Req *r, char *error)
{int n;
uchar *statbuf;
- uchar tmp[BIT16SZ];
if(error)
return;
- if(convD2M(&r->d, tmp, BIT16SZ) != BIT16SZ){- r->error = "convD2M(_,_,BIT16SZ) did not return BIT16SZ";
- return;
- }
- n = GBIT16(tmp)+BIT16SZ;
- if(n+BIT32SZ+BIT8SZ+BIT16SZ+BIT16SZ > r->srv->msize){- r->error = "rstat: message size too small";
- return;
- }
+ n = sizeD2M(&r->d);
statbuf = emalloc9p(n);
- r->ofcall.nstat = convD2M(&r->d, statbuf, n);
- if(r->ofcall.nstat <= BIT16SZ){- r->error = "convD2M fails";
+ n = convD2M(&r->d, statbuf, n);
+ if(n <= BIT16SZ || n > r->srv->msize-(BIT32SZ+BIT8SZ+BIT16SZ+BIT16SZ)){+ r->error = Emsize;
free(statbuf);
return;
}
+ r->ofcall.nstat = n;
r->ofcall.stat = statbuf; /* freed in closereq */
}
--
⑨