Received: from list by lists.gnu.org with archive (Exim 4.71) id 1f810q-0006TJ-FQ for mharc-grub-devel@gnu.org; Mon, 16 Apr 2018 06:05:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f810j-0006OQ-GQ for grub-devel@gnu.org; Mon, 16 Apr 2018 06:05:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f810g-0001qC-5M for grub-devel@gnu.org; Mon, 16 Apr 2018 06:05:21 -0400 Received: from prv3-mh.provo.novell.com ([137.65.250.26]:52327) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f810f-0001ib-Sr for grub-devel@gnu.org; Mon, 16 Apr 2018 06:05:18 -0400 Received: from mazu (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (TLS encrypted); Mon, 16 Apr 2018 04:05:09 -0600 Date: Mon, 16 Apr 2018 18:05:04 +0800 From: Michael Chang To: grub-devel@gnu.org Subject: [PATCH] bufio: fix the next_buf calculation Message-ID: <20180416100504.kbidvkerpritgigi@mazu> Mail-Followup-To: grub-devel@gnu.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: NeoMutt/20170421 (1.8.2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 137.65.250.26 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Apr 2018 10:05:27 -0000 The next_buf is the offset to the next cached block rounded to the size of bufio->block_size. However the calculation needs the block_size to be in power of 2 is not always valid. As an example, files with smaller size than block_size will have the block_size leveled to the size of file which can be set arbitrary value. This patch fixes the next_buf calculation to accept any integers. Signed-off-by: Michael Chang --- grub-core/io/bufio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/io/bufio.c b/grub-core/io/bufio.c index 22438277d..d0b0f71b6 100644 --- a/grub-core/io/bufio.c +++ b/grub-core/io/bufio.c @@ -132,7 +132,7 @@ grub_bufio_read (grub_file_t file, char *buf, grub_size_t len) return res; /* Need to read some more. */ - next_buf = (file->offset + res + len - 1) & ~((grub_off_t) bufio->block_size - 1); + next_buf = (grub_divmod64 (file->offset + res + len - 1, bufio->block_size, NULL)) * bufio->block_size; /* Now read between file->offset + res and bufio->buffer_at. */ if (file->offset + res < next_buf) { -- 2.13.6