devproc: fix close and closefiles procctl
for the CMclose procctl, the fd number was not bounds checked before indexing in the Fgrp.fd array. for the CMclosefiles, we looped fd from 0..maxfd-1, but need to loop from 0..maxfd as maxfd is inclusive.
This commit is contained in:
parent
c5214cd6d9
commit
89acedb9b8
1 changed files with 17 additions and 22 deletions
|
@ -1270,14 +1270,23 @@ procstopwait(Proc *p, int ctl)
|
|||
error(Eprocdied);
|
||||
}
|
||||
|
||||
static void
|
||||
procctlcloseone(Proc *p, Fgrp *f, int fd)
|
||||
void
|
||||
procctlclosefiles(Proc *p, int all, int fd)
|
||||
{
|
||||
Fgrp *f;
|
||||
Chan *c;
|
||||
|
||||
if(fd < 0)
|
||||
error(Ebadfd);
|
||||
f = p->fgrp;
|
||||
if(f == nil)
|
||||
error(Eprocdied);
|
||||
|
||||
lock(f);
|
||||
f->ref++;
|
||||
while(fd <= f->maxfd){
|
||||
c = f->fd[fd];
|
||||
if(c == nil)
|
||||
return;
|
||||
if(c != nil){
|
||||
f->fd[fd] = nil;
|
||||
unlock(f);
|
||||
qunlock(&p->debug);
|
||||
|
@ -1285,24 +1294,10 @@ procctlcloseone(Proc *p, Fgrp *f, int fd)
|
|||
qlock(&p->debug);
|
||||
lock(f);
|
||||
}
|
||||
|
||||
void
|
||||
procctlclosefiles(Proc *p, int all, int fd)
|
||||
{
|
||||
int i;
|
||||
Fgrp *f;
|
||||
|
||||
f = p->fgrp;
|
||||
if(f == nil)
|
||||
error(Eprocdied);
|
||||
|
||||
lock(f);
|
||||
f->ref++;
|
||||
if(all)
|
||||
for(i = 0; i < f->maxfd; i++)
|
||||
procctlcloseone(p, f, i);
|
||||
else
|
||||
procctlcloseone(p, f, fd);
|
||||
if(!all)
|
||||
break;
|
||||
fd++;
|
||||
}
|
||||
unlock(f);
|
||||
closefgrp(f);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue