Add checks to the read_io, seek_io and close_io routines to ensure that they do not perform any actions if an invalid

file handle (-1) is passed. This resolves the issue with extra arguments being left on the Forth stack when an invalid device 
access is attempted.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>


git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@764 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
Mark Cave-Ayland
2010-05-01 09:48:57 +00:00
committed by Mark Cave-Ayland
parent d183b53338
commit d2f9a689ac

View File

@@ -164,9 +164,12 @@ get_fstype( int fd )
int
read_io( int fd, void *buf, size_t cnt )
{
priv_fd_t *fdp = file_descriptors[fd];
priv_fd_t *fdp;
ucell ret;
if (fd != -1) {
fdp = file_descriptors[fd];
PUSH( (ucell)buf );
PUSH( cnt );
call_package( fdp->read_xt, fdp->ih );
@@ -174,17 +177,27 @@ read_io( int fd, void *buf, size_t cnt )
if( !ret && cnt )
ret = -1;
} else {
ret = -1;
}
return ret;
}
int
seek_io( int fd, llong offs )
{
priv_fd_t *fdp = file_descriptors[fd];
priv_fd_t *fdp;
if (fd != -1) {
fdp = file_descriptors[fd];
DPUSH( offs );
call_package( fdp->seek_xt, fdp->ih );
return ((((cell)POP()) >= 0)? 0 : -1);
} else {
return -1;
}
}
llong
@@ -203,13 +216,17 @@ tell( int fd )
int
close_io( int fd )
{
priv_fd_t *fdp = file_descriptors[fd];
priv_fd_t *fdp;
if (fd != -1) {
fdp = file_descriptors[fd];
if( fdp->do_close )
close_dev( fdp->ih );
free( fdp );
file_descriptors[fd]=NULL;
}
return 0;
}