kernel: make sure fd is in range in fdclose()

as the Fgrp can be shared with other processes, we have to
recheck the fd index after locking the Fgrp in fdclose()
to make sure not to read beyond the bounds of the fd array.
This commit is contained in:
cinap_lenrek 2015-07-23 22:56:49 +02:00
parent 323184d775
commit 497daed116

View file

@ -294,7 +294,7 @@ fdclose(int fd, int flag)
Fgrp *f = up->fgrp;
lock(f);
c = f->fd[fd];
c = fd <= f->maxfd ? f->fd[fd] : nil;
if(c == nil || (flag != 0 && (c->flag&flag) == 0)){
unlock(f);
return;