Check that the file offset is valid after a seek

This commit is contained in:
Sebastian Huber
2012-02-09 10:53:16 +01:00
parent 28860ec03c
commit e303adf444
2 changed files with 8 additions and 14 deletions

View File

@@ -500,21 +500,11 @@ msdos_dir_read(rtems_libio_t *iop, void *buffer, size_t count)
off_t off_t
msdos_dir_lseek(rtems_libio_t *iop, off_t offset, int whence) msdos_dir_lseek(rtems_libio_t *iop, off_t offset, int whence)
{ {
switch (whence) if (iop->offset >= 0 && iop->offset <= iop->size) {
{ return 0;
case SEEK_SET: } else {
case SEEK_CUR: rtems_set_errno_and_return_minus_one(EINVAL);
break;
/*
* Movement past the end of the directory via lseek is not a
* permitted operation
*/
case SEEK_END:
default:
rtems_set_errno_and_return_minus_one( EINVAL );
break;
} }
return RC_OK;
} }
/* msdos_dir_stat -- /* msdos_dir_stat --

View File

@@ -231,6 +231,10 @@ msdos_file_lseek(rtems_libio_t *iop, off_t offset, int whence)
fat_file_fd_t *fat_fd = iop->pathinfo.node_access; fat_file_fd_t *fat_fd = iop->pathinfo.node_access;
uint32_t real_size = 0; uint32_t real_size = 0;
if (iop->offset < 0 || iop->offset > UINT32_MAX) {
rtems_set_errno_and_return_minus_one(EINVAL);
}
sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT,
MSDOS_VOLUME_SEMAPHORE_TIMEOUT); MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
if (sc != RTEMS_SUCCESSFUL) if (sc != RTEMS_SUCCESSFUL)