Skip to content

Commit

Permalink
Fix attempt to rename root dir in fsck due to uninitialized fields
Browse files Browse the repository at this point in the history
When add_file() is called with offset 0, it will construct a DIR_ENT for
the root directory instead of reading the contents from the filesystem.
It did not initialize the whole DIR_ENT on the stack, just select
values.

In particular, the lcase field was left with an undefined value. If
that value happened to include the FAT_NO_83NAME bit, the "neither long
nor short file name" check in bad_name() added in 3.0.26 would trigger
and cause an attempt to rename the entry (which is not possible).
Example run:

    $ /sbin/fsck.fat -y bad.img
    fsck.fat 3.0.26 (2014-03-07)
    /
      Bad short file name ().
      Auto-renaming it.
      Renamed to
    bad.img: 14 files, 19388/403266 clusters

This commit changes the initialization zeroize the whole struct before
setting individual fields. Thanks to AlexisM, who found the cause and
posted a patch on the Debian bug http://bugs.debian.org/764992 .

Signed-off-by: Andreas Bombe <aeb@debian.org>
  • Loading branch information
andreasbombe committed Nov 11, 2014
1 parent c24ecb6 commit 82076b6
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -959,9 +959,9 @@ static void add_file(DOS_FS * fs, DOS_FILE *** chain, DOS_FILE * parent,
fs_read(offset, sizeof(DIR_ENT), &de);
else {
/* Construct a DIR_ENT for the root directory */
memset(&de, 0, sizeof de);
memcpy(de.name, " ", MSDOS_NAME);
de.attr = ATTR_DIR;
de.size = de.time = de.date = 0;
de.start = htole16(fs->root_cluster & 0xffff);
de.starthi = htole16((fs->root_cluster >> 16) & 0xffff);
}
Expand Down

0 comments on commit 82076b6

Please sign in to comment.