summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortobias <tobias@openbsd.org>2014-06-10 23:03:48 +0000
committertobias <tobias@openbsd.org>2014-06-10 23:03:48 +0000
commit7eea82b889133a7490229c76c8e1e904c0de612b (patch)
tree4e1e88a8579ff181d38c5e11983cf4025b2c7fa3
parentGroup ECC functions together to make things a little easier in -portable. (diff)
downloadwireguard-openbsd-7eea82b889133a7490229c76c8e1e904c0de612b.tar.xz
wireguard-openbsd-7eea82b889133a7490229c76c8e1e904c0de612b.zip
Fix off by one when writing FAT for FAT12 filesystems.
ok deraadt@
-rw-r--r--sbin/fsck_msdos/fat.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/sbin/fsck_msdos/fat.c b/sbin/fsck_msdos/fat.c
index 8d39e1a61b8..f10bf35da00 100644
--- a/sbin/fsck_msdos/fat.c
+++ b/sbin/fsck_msdos/fat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fat.c,v 1.19 2014/06/09 09:13:33 tobias Exp $ */
+/* $OpenBSD: fat.c,v 1.20 2014/06/10 23:03:48 tobias Exp $ */
/* $NetBSD: fat.c,v 1.8 1997/10/17 11:19:53 ws Exp $ */
/*
@@ -471,13 +471,15 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat)
default:
if (fat[cl].next == CLUST_FREE)
boot->NumFree++;
- if (cl + 1 < boot->NumClusters
- && fat[cl + 1].next == CLUST_FREE)
- boot->NumFree++;
*p++ = (u_char)fat[cl].next;
- *p++ = (u_char)((fat[cl].next >> 8) & 0xf)
- |(u_char)(fat[cl+1].next << 4);
- *p++ = (u_char)(fat[++cl].next >> 4);
+ *p++ = (u_char)((fat[cl].next >> 8) & 0xf);
+ cl++;
+ if (cl >= boot->NumClusters)
+ break;
+ if (fat[cl].next == CLUST_FREE)
+ boot->NumFree++;
+ *p |= (u_char)(fat[cl].next << 4);
+ *p++ = (u_char)(fat[cl].next >> 4);
break;
}
}