summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2021-11-04 17:33:14 -0700
committerXin Li <delphij@google.com>2021-11-04 17:34:08 -0700
commit0f429e88ff7c3135548fa820fe3bda3f90f998f0 (patch)
tree74b106e081ec97afca7cc2b7caa5992227b9c12b
parentc5147bee1c421890bd0d7903dce24b516d381025 (diff)
parentd46acd8389628eedce39706c71e71f269008a0b4 (diff)
downloadfsck_msdos-0f429e88ff7c3135548fa820fe3bda3f90f998f0.tar.gz
fsck_msdosfs: truncate directory entry when the head pointer is invalid.
Sync with upstream (890cae197737b463e56d1cc5a3f61f84cb49c807). Bug: 205193362 Fixed: 205193362 Tests: run fsck_msdos on disk image Change-Id: Idf5a59c2b1951ca51e996b44fa62d72c3d82f81c
-rw-r--r--dir.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/dir.c b/dir.c
index 010bd65..dbe4e0c 100644
--- a/dir.c
+++ b/dir.c
@@ -400,8 +400,21 @@ checksize(struct fat_descriptor *fat, u_char *p, struct dosDirEntry *dir)
if (dir->head == CLUST_FREE) {
physicalSize = 0;
} else {
- if (!fat_is_valid_cl(fat, dir->head))
- return FSERROR;
+ if (!fat_is_valid_cl(fat, dir->head) || !fat_is_cl_head(fat, dir->head)) {
+ pwarn("Directory entry %s of size %u referencing invalid cluster %u\n",
+ fullpath(dir), dir->size, dir->head);
+ if (ask(1, "Truncate")) {
+ p[28] = p[29] = p[30] = p[31] = 0;
+ p[26] = p[27] = 0;
+ if (boot->ClustMask == CLUST32_MASK)
+ p[20] = p[21] = 0;
+ dir->size = 0;
+ dir->head = CLUST_FREE;
+ return FSDIRMOD;
+ } else {
+ return FSERROR;
+ }
+ }
ret = checkchain(fat, dir->head, &chainsize);
/*
* Upon return, chainsize would hold the chain length
@@ -422,8 +435,8 @@ checksize(struct fat_descriptor *fat, u_char *p, struct dosDirEntry *dir)
physicalSize = (u_int64_t)chainsize * boot->ClusterSize;
}
if (physicalSize < dir->size) {
- pwarn("size of %s is %u, should at most be %" PRIu64 "\n",
- fullpath(dir), dir->size, physicalSize);
+ pwarn("size of %s is %u, should at most be %ju\n",
+ fullpath(dir), dir->size, (uintmax_t)physicalSize);
if (ask(1, "Truncate")) {
dir->size = physicalSize;
p[28] = (u_char)physicalSize;