From b3f20f8c5b7533dc203460fd667ea4f4b99e61c3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 23 May 2018 08:14:22 -0600 Subject: [PATCH] fs/fat: In fs_stat(), when stat'ing the root directory, avoid calculating the address of the root directory entry. The calculation is bogus (but not harmful) because the root directory does not have a directory entry. Noted by Boris Astardzhiev. --- fs/fat/fs_fat32.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/fat/fs_fat32.c b/fs/fat/fs_fat32.c index 30c8ce1c3a..5e696556d6 100644 --- a/fs/fat/fs_fat32.c +++ b/fs/fat/fs_fat32.c @@ -115,7 +115,7 @@ static int fat_stat_common(FAR struct fat_mountpt_s *fs, static int fat_stat_file(FAR struct fat_mountpt_s *fs, FAR uint8_t *direntry, FAR struct stat *buf); static int fat_stat_root(FAR struct fat_mountpt_s *fs, - FAR uint8_t *direntry, FAR struct stat *buf); + FAR struct stat *buf); static int fat_stat(struct inode *mountpt, const char *relpath, FAR struct stat *buf); @@ -2807,8 +2807,7 @@ static int fat_stat_file(FAR struct fat_mountpt_s *fs, * ****************************************************************************/ -static int fat_stat_root(FAR struct fat_mountpt_s *fs, - FAR uint8_t *direntry, FAR struct stat *buf) +static int fat_stat_root(FAR struct fat_mountpt_s *fs, FAR struct stat *buf) { /* Clear the "struct stat" */ @@ -2865,18 +2864,18 @@ static int fat_stat(FAR struct inode *mountpt, FAR const char *relpath, goto errout_with_semaphore; } - /* Get a pointer to the directory entry */ - - direntry = &fs->fs_buffer[dirinfo.fd_seq.ds_offset]; - /* Get the FAT attribute and map it so some meaningful mode_t values */ if (dirinfo.fd_root) { - ret = fat_stat_root(fs, direntry, buf); + ret = fat_stat_root(fs, buf); } else { + /* Get a pointer to the directory entry */ + + direntry = &fs->fs_buffer[dirinfo.fd_seq.ds_offset]; + /* Call fat_stat_file() to create the buf and to save information to * the stat buffer. */