[OpenBIOS] [commit] r764 - trunk/openbios-devel/libc
repository service
svn at openbios.org
Sat May 1 11:48:57 CEST 2010
Author: mcayland
Date: Sat May 1 11:48:57 2010
New Revision: 764
URL: http://tracker.coreboot.org/trac/openbios/changeset/764
Log:
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 at siriusit.co.uk>
Modified:
trunk/openbios-devel/libc/diskio.c
Modified: trunk/openbios-devel/libc/diskio.c
==============================================================================
--- trunk/openbios-devel/libc/diskio.c Fri Apr 30 23:56:29 2010 (r763)
+++ trunk/openbios-devel/libc/diskio.c Sat May 1 11:48:57 2010 (r764)
@@ -164,27 +164,40 @@
int
read_io( int fd, void *buf, size_t cnt )
{
- priv_fd_t *fdp = file_descriptors[fd];
+ priv_fd_t *fdp;
ucell ret;
- PUSH( (ucell)buf );
- PUSH( cnt );
- call_package( fdp->read_xt, fdp->ih );
- ret = POP();
+ if (fd != -1) {
+ fdp = file_descriptors[fd];
- if( !ret && cnt )
+ PUSH( (ucell)buf );
+ PUSH( cnt );
+ call_package( fdp->read_xt, fdp->ih );
+ ret = POP();
+
+ 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;
- DPUSH( offs );
- call_package( fdp->seek_xt, fdp->ih );
- return ((((cell)POP()) >= 0)? 0 : -1);
+ 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 @@
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 );
+ if( fdp->do_close )
+ close_dev( fdp->ih );
+ free( fdp );
- file_descriptors[fd]=NULL;
+ file_descriptors[fd]=NULL;
+ }
return 0;
}
More information about the OpenBIOS
mailing list