ref: ff3e0eeb22816208360db3c87e501c5de7d998e3
parent: 3df95385bcc5294a212534d0991f1ffef1454aca
author: cinap_lenrek <[email protected]>
date: Fri Feb 28 11:41:09 EST 2020
devproc: cleanup procwrite size checks writes to /proc/n/notepg and /proc/n/note should be able to write at ERRMAX-1 bytes, not ERRMAX-2. simplify write to /proc/n/args by just copying to local buf first and then doing a kstrdup(). the value of Proc.nargs does not matter when Proc.setargs is 1.
--- a/sys/src/9/port/devproc.c
+++ b/sys/src/9/port/devproc.c
@@ -1154,10 +1154,9 @@
static long
procwrite(Chan *c, void *va, long n, vlong off)
{
- char buf[ERRMAX], *arg;
+ char buf[ERRMAX];
ulong offset;
Proc *p;
- int m;
offset = off;
if(c->qid.type & QTDIR)
@@ -1165,7 +1164,7 @@
/* use the remembered noteid in the channel qid */
if(QID(c->qid) == Qnotepg) {
- if(n >= ERRMAX-1)
+ if(n >= sizeof(buf))
error(Etoobig);
memmove(buf, va, n);
buf[n] = 0;
@@ -1184,20 +1183,12 @@
switch(QID(c->qid)){
case Qargs:
- if(n == 0)
- error(Eshort);
- if(n >= ERRMAX)
+ if(offset != 0 || n >= sizeof(buf))
error(Etoobig);
- arg = malloc(n+1);
- if(arg == nil)
- error(Enomem);
- memmove(arg, va, n);
- m = n;
- if(arg[m-1] != 0)
- arg[m++] = 0;
- free(p->args);
- p->args = arg;
- p->nargs = m;
+ memmove(buf, va, n);
+ buf[n] = 0;
+ kstrdup(&p->args, buf);
+ p->nargs = 0;
p->setargs = 1;
break;
@@ -1241,7 +1232,7 @@
break;
case Qnoteid:
- if(n >= sizeof(buf))
+ if(offset != 0 || n >= sizeof(buf))
error(Etoobig);
memmove(buf, va, n);
buf[n] = 0;