Changeset 638 for soft


Ignore:
Timestamp:
Jul 20, 2015, 6:02:55 PM (9 years ago)
Author:
guerin
Message:

fat32: disallow move into own subdirectory

"mv / home/a" would crash,
"mv home home/sub" would unfortunately succeed.

File:
1 edited

Legend:

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

    r637 r638  
    309309static unsigned int _get_inode_from_path( char*          pathname,
    310310                                          fat_inode_t**  inode );
     311
     312//////////////////////////////////////////////////////////////////////////////////
     313// The following function checks if node "a" is an ancestor of inode "b".
     314// It returns 0 on failure.
     315// It returns 1 otherwise.
     316//////////////////////////////////////////////////////////////////////////////////
     317
     318static unsigned int _is_ancestor( fat_inode_t* a,
     319                                  fat_inode_t* b);
    311320
    312321//////////////////////////////////////////////////////////////////////////////////
     
    15751584    }
    15761585}  // end _add_special_directories
     1586
     1587
     1588
     1589////////////////////////////////////////////////////////////
     1590static unsigned int _is_ancestor( fat_inode_t* a,
     1591                                  fat_inode_t* b )
     1592{
     1593    while ( b )
     1594    {
     1595        if ( a == b )
     1596            return 1;
     1597
     1598        b = b->parent;
     1599    }
     1600
     1601    return 0;
     1602} // _is_ancestor()
    15771603
    15781604
     
    37343760//  -10 : "cannot update old_parent directory on device"
    37353761//  -11 : "cannot remove to_remove node from FS"
     3762//  -12 : "cannot move into its own subdirectory"
    37363763/////////////////////////////////////////////////////////////////////////////////
    37373764int _fat_rename( char*  old_path,
     
    38033830        _printf("\n[FAT ERROR] in _fat_rename() : <%s> not found\n", new_path );
    38043831        return -3;
     3832    }
     3833
     3834    // check for move into own subdirectory
     3835    if ( _is_ancestor( old, new_parent ) )
     3836    {
     3837        _spin_lock_release( &_fat.fat_lock );
     3838        _printf("\n[FAT ERROR] in _fat_rename() : can't move %s into its own subdirectory\n", old_path );
     3839        return -12;
    38053840    }
    38063841
Note: See TracChangeset for help on using the changeset viewer.