NetBSD Problem Report #36613

From martin@duskware.de  Sat Jul  7 10:27:21 2007
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id 80B8963B874
	for <gnats-bugs@gnats.netbsd.org>; Sat,  7 Jul 2007 10:27:21 +0000 (UTC)
Message-Id: <20070707083126.CCCD263B89E@narn.NetBSD.org>
Date: Sat,  7 Jul 2007 08:31:26 +0000 (UTC)
From: Todd.Miller@courtesan.com
Reply-To: Todd.Miller@courtesan.com
To: netbsd-bugs-owner@NetBSD.org
Subject: newfs: wrong value used for loop max when initializing the first 2 blocks of inodes
X-Send-Pr-Version: www-1.0

>Number:         36613
>Category:       bin
>Synopsis:       newfs: wrong value used for loop max when initializing the first 2 blocks of inodes
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 07 10:30:00 +0000 2007
>Originator:     Todd C. Miller
>Release:        -current
>Organization:
>Environment:
>Description:
In newfs/mkfs.c the wrong value used for loop max when initializing the first 2 blocks of inodes in initcg().  The bug is unlikely to surface since sblock.fs_ipg < 2 * INOPB(&sblock) in just about any conceivable case.

The enclosed diff (which you'll have to apply by hand since this is a web submission) also make the assignment of acg.cg_initediblk use MIN() for consistency. 
>How-To-Repeat:
inspect code, exclaim eureka
>Fix:
Index: mkfs.c
===================================================================
RCS file: /home/cvs/netbsd/src/sbin/newfs/mkfs.c,v
retrieving revision 1.102
diff -u -r1.102 mkfs.c
--- mkfs.c      16 Oct 2006 03:04:45 -0000      1.102
+++ mkfs.c      7 Jul 2007 08:20:46 -0000
@@ -769,8 +769,7 @@
        if (Oflag == 2) {
                acg.cg_time = tv->tv_sec;
                acg.cg_niblk = sblock.fs_ipg;
-               acg.cg_initediblk = sblock.fs_ipg < 2 * INOPB(&sblock) ?
-                   sblock.fs_ipg : 2 * INOPB(&sblock);
+               acg.cg_initediblk = MIN(sblock.fs_ipg, 2 * INOPB(&sblock));
                acg.cg_iusedoff = start;
        } else {
                acg.cg_old_ncyl = sblock.fs_old_cpg;
@@ -916,7 +915,7 @@
        start += sblock.fs_bsize;
        dp1 = (struct ufs1_dinode *)(&iobuf[start]);
        dp2 = (struct ufs2_dinode *)(&iobuf[start]);
-       for (i = MIN(sblock.fs_ipg, 2) * INOPB(&sblock); i != 0; i--) {
+       for (i = MIN(sblock.fs_ipg, 2 * INOPB(&sblock)); i != 0; i--) {
                if (sblock.fs_magic == FS_UFS1_MAGIC) {
                        /* No need to swap, it'll stay random */
                        dp1->di_gen = arc4random() & INT32_MAX;

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.