Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F111637229
D23082.id66585.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D23082.id66585.diff
View Options
Index: sbin/fsck_msdosfs/boot.c
===================================================================
--- sbin/fsck_msdosfs/boot.c
+++ sbin/fsck_msdosfs/boot.c
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: boot.c,v 1.11 2006/06/05 16:51:18 christos Exp ");
+__RCSID("$NetBSD: boot.c,v 1.21 2018/02/08 09:05:17 dholland Exp $");
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
@@ -250,7 +250,7 @@
boot->FATsecs = boot->bpbFATsmall;
}
- if (boot->FATsecs > UINT32_MAX / boot->bpbFATs) {
+ if (boot->FATsecs < 1 || boot->FATsecs > UINT32_MAX / boot->bpbFATs) {
pfatal("Invalid FATs(%u) with FATsecs(%zu)",
boot->bpbFATs, (size_t)boot->FATsecs);
return FSFATAL;
@@ -266,8 +266,11 @@
return FSFATAL;
}
- boot->NumClusters = (boot->NumSectors - boot->FirstCluster) / boot->bpbSecPerClust +
- CLUST_FIRST;
+ /*
+ * The number of clusters is derived from available data sectors, divided
+ * by sectors per cluster.
+ */
+ boot->NumClusters = (boot->NumSectors - boot->FirstCluster) / boot->bpbSecPerClust;
if (boot->flags & FAT32) {
if (boot->NumClusters > (CLUST_RSRVD & CLUST32_MASK)) {
@@ -310,11 +313,19 @@
break;
}
- if (boot->NumFatEntries < boot->NumClusters - CLUST_FIRST) {
+ if (boot->NumFatEntries < boot->NumClusters) {
pfatal("FAT size too small, %u entries won't fit into %u sectors\n",
boot->NumClusters, boot->FATsecs);
return FSFATAL;
}
+
+ /*
+ * There are two reserved clusters. To avoid adding CLUST_FIRST every time
+ * when we perform boundary checks, we increment the NumClusters by 2,
+ * which is CLUST_FIRST to denote the first out-of-range cluster number.
+ */
+ boot->NumClusters += CLUST_FIRST;
+
boot->ClusterSize = boot->bpbBytesPerSec * boot->bpbSecPerClust;
boot->NumFiles = 1;
@@ -356,7 +367,7 @@
* support for FAT32) doesn't maintain the FSINFO block
* correctly, it has to be fixed pretty often.
*
- * Therefor, we handle the FSINFO block only informally,
+ * Therefore, we handle the FSINFO block only informally,
* fixing it if necessary, but otherwise ignoring the
* fact that it was incorrect.
*/
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 7, 8:30 AM (19 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
17028539
Default Alt Text
D23082.id66585.diff (2 KB)
Attached To
Mode
D23082: sbin/fsck_msdosfs: Correct off-by-two issue when determining FAT type.
Attached
Detach File
Event Timeline
Log In to Comment