Ignore:
Timestamp:
Nov 21, 2015, 2:57:45 PM (9 years ago)
Author:
alain
Message:

Improve seek overflow checking.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/giet_fat32/fat32.c

    r709 r730  
    31983198/////////////////////////////////////////////////////////////////////////////////
    31993199// Returns the number of bytes actually transfered on success.
    3200 // Returns 0 if EOF is encountered (offset + count > file_size).
    32013200// Returns a negative value on error:
    32023201//   GIET_FAT32_NOT_INITIALIZED,
     
    32493248    _spin_lock_acquire( &_fat.fat_lock );
    32503249    _atomic_or( &psched->context[ltid].slot[CTX_LOCKS_ID] , LOCKS_MASK_FAT );
    3251 
    32523250           
    32533251    // get file inode pointer and offset
     
    32553253    unsigned int seek   = _fat.fd[fd_id].seek;
    32563254
    3257     // check count & seek versus file size
    3258     if ( count + seek > inode->size && !inode->is_dir )
     3255    // check seek versus file size
     3256    if ( (seek >= inode->size) && !inode->is_dir )
    32593257    {
    32603258        _spin_lock_release( &_fat.fat_lock );
    32613259        _atomic_and( &psched->context[ltid].slot[CTX_LOCKS_ID] , ~LOCKS_MASK_FAT );
    32623260
    3263         _printf("\n[FAT ERROR] _fat_read(): file too small"
    3264                 " / seek = %x / count = %x / file_size = %x\n",
    3265                 seek , count , inode->size );
    3266         return 0;
    3267     }
     3261        _printf("\n[FAT ERROR] _fat_read(): seek larger than file size"
     3262                " / seek = %x / file_size = %x\n",
     3263                seek , inode->size );
     3264        return GIET_FAT32_IO_ERROR;
     3265    }
     3266
     3267    // check and ajust count argument
     3268    if ( count > (inode->size - seek) ) count = inode->size - seek;
    32683269
    32693270    // compute first_cluster_id and first_byte_to_move
Note: See TracChangeset for help on using the changeset viewer.