Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/fsck_msdos From: http://marc.info/?l=openbsd-tech&m=140...



details:   https://anonhg.NetBSD.org/src/rev/507935d30d2b
branches:  trunk
changeset: 330403:507935d30d2b
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Jul 07 18:46:45 2014 +0000

description:
From: http://marc.info/?l=openbsd-tech&m=140234174104724&w=2
Avoid off-by-one on FAT12 filesystems.

diffstat:

 sbin/fsck_msdos/fat.c |  18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)

diffs (40 lines):

diff -r b58310e9b5f2 -r 507935d30d2b sbin/fsck_msdos/fat.c
--- a/sbin/fsck_msdos/fat.c     Mon Jul 07 17:55:53 2014 +0000
+++ b/sbin/fsck_msdos/fat.c     Mon Jul 07 18:46:45 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fat.c,v 1.26 2014/07/07 17:55:53 christos Exp $        */
+/*     $NetBSD: fat.c,v 1.27 2014/07/07 18:46:45 christos Exp $        */
 
 /*
  * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: fat.c,v 1.26 2014/07/07 17:55:53 christos Exp $");
+__RCSID("$NetBSD: fat.c,v 1.27 2014/07/07 18:46:45 christos Exp $");
 #endif /* not lint */
 
 #include <stdlib.h>
@@ -554,13 +554,15 @@
                default:
                        if (fat[cl].next == CLUST_FREE)
                                boot->NumFree++;
-                       if (cl + 1 < boot->NumClusters
-                           && fat[cl + 1].next == CLUST_FREE)
+                       *p++ = (u_char)fat[cl].next;
+                       *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;
-                       *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 + 1].next << 4);
+                       *p++ = (u_char)(fat[cl + 1].next >> 4);
                        break;
                }
        }



Home | Main Index | Thread Index | Old Index