fix major validation
fileread/filewrite should validate major to avoid buffer overflows or bogus function pointers.
This commit is contained in:
parent
37df68e5de
commit
9ead904afe
|
@ -114,6 +114,8 @@ fileread(struct file *f, uint64 addr, int n)
|
|||
if(f->type == FD_PIPE){
|
||||
r = piperead(f->pipe, addr, n);
|
||||
} else if(f->type == FD_DEVICE){
|
||||
if(f->major < 0 || f->major >= NDEV || !devsw[f->major].read)
|
||||
return -1;
|
||||
r = devsw[f->major].read(1, addr, n);
|
||||
} else if(f->type == FD_INODE){
|
||||
ilock(f->ip);
|
||||
|
@ -140,6 +142,8 @@ filewrite(struct file *f, uint64 addr, int n)
|
|||
if(f->type == FD_PIPE){
|
||||
ret = pipewrite(f->pipe, addr, n);
|
||||
} else if(f->type == FD_DEVICE){
|
||||
if(f->major < 0 || f->major >= NDEV || !devsw[f->major].write)
|
||||
return -1;
|
||||
ret = devsw[f->major].write(1, addr, n);
|
||||
} else if(f->type == FD_INODE){
|
||||
// write a few blocks at a time to avoid exceeding
|
||||
|
|
Loading…
Reference in a new issue