[rtems commit] Check that the file offset is valid after a seek

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Feb 10 21:46:50 UTC 2012


The lseek and truncate mechanic is completely broken (just look at the 
fstests).  This patch is not sufficient and it is work in progress.

On 10/02/12 19:33, Joel Sherrill wrote:
>
> This looks like something that should also be on the 4.10 branch
> with a PR.
>
> What do you think?
>
> --joel
>
> On 02/09/2012 04:08 AM, Sebastian Huber wrote:
>> Module:    rtems
>> Branch:    master
>> Commit:    e303adf4445919d4d87e8467854c404f9bd0d076
>> Changeset: 
>> http://git.rtems.org/rtems/commit/?id=e303adf4445919d4d87e8467854c404f9bd0d076
>>
>> Author:    Sebastian Huber<sebastian.huber at embedded-brains.de>
>> Date:      Thu Feb  9 10:53:16 2012 +0100
>>
>> Check that the file offset is valid after a seek
>>
>> ---
>>
>>   cpukit/libfs/src/dosfs/msdos_dir.c  |   18 ++++--------------
>>   cpukit/libfs/src/dosfs/msdos_file.c |    4 ++++
>>   2 files changed, 8 insertions(+), 14 deletions(-)
>>
>> diff --git a/cpukit/libfs/src/dosfs/msdos_dir.c 
>> b/cpukit/libfs/src/dosfs/msdos_dir.c
>> index 9a8ed1e..a0ef507 100644
>> --- a/cpukit/libfs/src/dosfs/msdos_dir.c
>> +++ b/cpukit/libfs/src/dosfs/msdos_dir.c
>> @@ -500,21 +500,11 @@ msdos_dir_read(rtems_libio_t *iop, void 
>> *buffer, size_t count)
>>   off_t
>>   msdos_dir_lseek(rtems_libio_t *iop, off_t offset, int whence)
>>   {
>> -    switch (whence)
>> -    {
>> -        case SEEK_SET:
>> -        case SEEK_CUR:
>> -            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;
>> +    if (iop->offset>= 0&&  iop->offset<= iop->size) {
>> +        return 0;
>> +    } else {
>> +        rtems_set_errno_and_return_minus_one(EINVAL);
>>       }
>> -    return RC_OK;
>>   }
>>
>>   /* msdos_dir_stat --
>> diff --git a/cpukit/libfs/src/dosfs/msdos_file.c 
>> b/cpukit/libfs/src/dosfs/msdos_file.c
>> index b0eeba9..5378a25 100644
>> --- a/cpukit/libfs/src/dosfs/msdos_file.c
>> +++ b/cpukit/libfs/src/dosfs/msdos_file.c
>> @@ -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;
>>       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,
>>                                   MSDOS_VOLUME_SEMAPHORE_TIMEOUT);
>>       if (sc != RTEMS_SUCCESSFUL)
>>
>> _______________________________________________
>> rtems-vc mailing list
>> rtems-vc at rtems.org
>> http://www.rtems.org/mailman/listinfo/rtems-vc
>
>


-- 
Sebastian Huber, embedded brains GmbH

Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany
Phone   : +49 89 18 90 80 79-6
Fax     : +49 89 18 90 80 79-9
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.




More information about the devel mailing list