File dosfstools-fix-attempt-to-rename-root-dir.patch of Package dosfstools.2621
From 82076b64ccc1bd18d854982f9c01d369a665ff65 Mon Sep 17 00:00:00 2001
From: Andreas Bombe <aeb@debian.org>
Date: Tue, 11 Nov 2014 23:25:30 +0100
Subject: [PATCH] Fix attempt to rename root dir in fsck due to uninitialized
fields
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>
---
src/check.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git src/check.c src/check.c
index a330caf..e8aaf92 100644
--- src/check.c
+++ src/check.c
@@ -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);
}