diff options
| author | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-02-28 16:41:09 +0100 |
|---|---|---|
| committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-02-28 16:41:09 +0100 |
| commit | ff3e0eeb22816208360db3c87e501c5de7d998e3 (patch) | |
| tree | 7f67b5942031926fedefcf4c766ba74bc2342fc6 | |
| parent | 3df95385bcc5294a212534d0991f1ffef1454aca (diff) | |
| download | plan9front-ff3e0eeb22816208360db3c87e501c5de7d998e3.tar.xz | |
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.
| -rw-r--r-- | sys/src/9/port/devproc.c | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/sys/src/9/port/devproc.c b/sys/src/9/port/devproc.c index 940fbeb16..b2509ddcb 100644 --- a/sys/src/9/port/devproc.c +++ b/sys/src/9/port/devproc.c @@ -1154,10 +1154,9 @@ procread(Chan *c, void *va, long n, vlong off) 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 @@ procwrite(Chan *c, void *va, long n, vlong off) /* 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 @@ procwrite(Chan *c, void *va, long n, vlong off) 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 @@ procwrite(Chan *c, void *va, long n, vlong off) break; case Qnoteid: - if(n >= sizeof(buf)) + if(offset != 0 || n >= sizeof(buf)) error(Etoobig); memmove(buf, va, n); buf[n] = 0; |
