Source-Changes-HG archive

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

[src/trunk]: src/sys/ufs/ffs ffs_appleufs_validate():



details:   https://anonhg.NetBSD.org/src/rev/278a963720dc
branches:  trunk
changeset: 336135:278a963720dc
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Feb 14 08:07:39 2015 +0000

description:
ffs_appleufs_validate():
 - remove superfluous printfs
 - ensure ul_namelen!=0, otherwise the kernel accesses ul_name[-1] and
   overwrites the previous field in the structure.

diffstat:

 sys/ufs/ffs/ffs_appleufs.c |  25 ++++++++-----------------
 1 files changed, 8 insertions(+), 17 deletions(-)

diffs (53 lines):

diff -r 4657956ece34 -r 278a963720dc sys/ufs/ffs/ffs_appleufs.c
--- a/sys/ufs/ffs/ffs_appleufs.c        Sat Feb 14 07:56:31 2015 +0000
+++ b/sys/ufs/ffs/ffs_appleufs.c        Sat Feb 14 08:07:39 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs_appleufs.c,v 1.13 2015/02/14 07:56:31 maxv Exp $   */
+/*     $NetBSD: ffs_appleufs.c,v 1.14 2015/02/14 08:07:39 maxv Exp $   */
 
 /*
  * Copyright (c) 2002 Darrin B. Jewell
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ffs_appleufs.c,v 1.13 2015/02/14 07:56:31 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ffs_appleufs.c,v 1.14 2015/02/14 08:07:39 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -89,28 +89,19 @@
                return EINVAL;
 
        *n = *o;
-       n->ul_checksum = 0;
        n->ul_checksum = ffs_appleufs_cksum(n);
-       if (n->ul_checksum != o->ul_checksum) {
-#if defined(DIAGNOSTIC) || !defined(_KERNEL)
-               printf("%s: invalid APPLE UFS checksum. found 0x%x, expecting 0x%x",
-                   name, o->ul_checksum, n->ul_checksum);
-#endif
-               return EINVAL;
-       }
        n->ul_magic = be32toh(o->ul_magic);
        n->ul_version = be32toh(o->ul_version);
        n->ul_time = be32toh(o->ul_time);
        n->ul_namelen = be16toh(o->ul_namelen);
 
-       if (n->ul_namelen > APPLEUFS_MAX_LABEL_NAME) {
-#if defined(DIAGNOSTIC) || !defined(_KERNEL)
-               printf("%s: APPLE UFS label name too long, truncated.\n",
-                   name);
-#endif
+       if (n->ul_checksum != o->ul_checksum)
+               return EINVAL;
+       if (n->ul_namelen == 0)
+               return EINVAL;
+       if (n->ul_namelen > APPLEUFS_MAX_LABEL_NAME)
                n->ul_namelen = APPLEUFS_MAX_LABEL_NAME;
-       }
-       /* if len is max, will set ul_unused1 */
+
        n->ul_name[n->ul_namelen - 1] = '\0';
 
 #ifdef DEBUG



Home | Main Index | Thread Index | Old Index