diff options
author | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2014-06-10 23:03:49 +0000 |
---|---|---|
committer | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2014-06-10 23:03:49 +0000 |
commit | 1da3b76566507f7b2cb274e4c3d095dc9529542f (patch) | |
tree | eab4a53ade42f0ccb3024a08f0d7475965103de3 | |
parent | ff01a08e168005630ffd154331b06d4b987aa4b8 (diff) |
Fix off by one when writing FAT for FAT12 filesystems.
ok deraadt@
-rw-r--r-- | sbin/fsck_msdos/fat.c | 16 |
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; } } |