From owner-svn-src-all@freebsd.org Tue Jun 26 06:19:00 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2A89B1012EB1; Tue, 26 Jun 2018 06:19:00 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C8D4881890; Tue, 26 Jun 2018 06:18:59 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9C8CF10795; Tue, 26 Jun 2018 06:18:59 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5Q6Ixjs005817; Tue, 26 Jun 2018 06:18:59 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5Q6Ix2j005816; Tue, 26 Jun 2018 06:18:59 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201806260618.w5Q6Ix2j005816@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Tue, 26 Jun 2018 06:18:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335655 - head/sbin/fsck_msdosfs X-SVN-Group: head X-SVN-Commit-Author: delphij X-SVN-Commit-Paths: head/sbin/fsck_msdosfs X-SVN-Commit-Revision: 335655 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2018 06:19:00 -0000 Author: delphij Date: Tue Jun 26 06:18:59 2018 New Revision: 335655 URL: https://svnweb.freebsd.org/changeset/base/335655 Log: Fix division by zero when reading boot block by postponing division until it is necessary and after we validated bytes per sector is non- zero. Obtained from: Android https://android-review.googlesource.com/c/platform/external/fsck_msdos/+/36362 MFC after: 2 weeks Modified: head/sbin/fsck_msdosfs/boot.c Modified: head/sbin/fsck_msdosfs/boot.c ============================================================================== --- head/sbin/fsck_msdosfs/boot.c Tue Jun 26 04:06:49 2018 (r335654) +++ head/sbin/fsck_msdosfs/boot.c Tue Jun 26 06:18:59 2018 (r335655) @@ -178,12 +178,8 @@ readboot(int dosfs, struct bootblock *boot) /* Check backup bpbFSInfo? XXX */ } - boot->ClusterOffset = (boot->bpbRootDirEnts * 32 + - boot->bpbBytesPerSec - 1) / boot->bpbBytesPerSec + - boot->bpbResSectors + boot->bpbFATs * boot->FATsecs - - CLUST_FIRST * boot->bpbSecPerClust; - - if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE_REAL != 0) { + if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE_REAL != 0 || + boot->bpbBytesPerSec == 0) { pfatal("Invalid sector size: %u", boot->bpbBytesPerSec); return FSFATAL; } @@ -196,6 +192,10 @@ readboot(int dosfs, struct bootblock *boot) boot->NumSectors = boot->bpbSectors; } else boot->NumSectors = boot->bpbHugeSectors; + boot->ClusterOffset = (boot->bpbRootDirEnts * 32 + + boot->bpbBytesPerSec - 1) / boot->bpbBytesPerSec + + boot->bpbResSectors + boot->bpbFATs * boot->FATsecs - + CLUST_FIRST * boot->bpbSecPerClust; boot->NumClusters = (boot->NumSectors - boot->ClusterOffset) / boot->bpbSecPerClust;