Received: from list by lists.gnu.org with archive (Exim 4.71) id 1hRYjI-0001ml-Tn for mharc-grub-devel@gnu.org; Fri, 17 May 2019 05:00:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRYjC-0001mC-51 for grub-devel@gnu.org; Fri, 17 May 2019 05:00:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRYjA-00088T-Ol for grub-devel@gnu.org; Fri, 17 May 2019 05:00:34 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:60898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hRYjA-000870-Fq for grub-devel@gnu.org; Fri, 17 May 2019 05:00:32 -0400 Received: from localhost.localdomain (prva10-snat226-2.provo.novell.com [137.65.226.36]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Fri, 17 May 2019 03:00:22 -0600 From: Michael Chang To: grub-devel@gnu.org Subject: [PATCH] f2fs: Fix gcc9 error -Werror=maybe-uninitialized Date: Fri, 17 May 2019 17:00:19 +0800 Message-Id: <20190517090019.8357-1-mchang@suse.com> X-Mailer: git-send-email 2.16.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.250.81 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: Fri, 17 May 2019 09:00:39 -0000 The function grub_get_node_path could return uninitialized offset with level == 0 if the block is greater than direct_index + 2*direct_blks + 2*indirect_blks + dindirect_blks. The uninitialized offset is then used by function grub_f2fs_get_block because level == 0 is valid and meaningful return to be processed. The fix is to set level = -1 as return value by grub_get_node_path to signify an error that the input block cannot be handled. Any caller should therefore check level is negative or not before processing the output. Reported-by: Neil MacLeod Signed-off-by: Michael Chang --- grub-core/fs/f2fs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c index 644653dbe..bb28b291b 100644 --- a/grub-core/fs/f2fs.c +++ b/grub-core/fs/f2fs.c @@ -702,7 +702,7 @@ grub_get_node_path (struct grub_f2fs_inode *inode, grub_uint32_t block, grub_uint32_t dindirect_blks = indirect_blks * NIDS_PER_BLOCK; grub_uint32_t direct_index = DEF_ADDRS_PER_INODE; int n = 0; - int level = 0; + int level = -1; if (inode->i_inline & F2FS_INLINE_XATTR) direct_index -= F2FS_INLINE_XATTR_ADDRS; @@ -712,6 +712,7 @@ grub_get_node_path (struct grub_f2fs_inode *inode, grub_uint32_t block, if (block < direct_index) { offset[n] = block; + level = 0; goto got; } @@ -860,6 +861,10 @@ grub_f2fs_get_block (grub_fshelp_node_t node, grub_disk_addr_t block_ofs) int level, i; level = grub_get_node_path (inode, block_ofs, offset, noffset); + + if (level < 0) + return -1; + if (level == 0) return grub_le_to_cpu32 (inode->i_addr[offset[0]]); -- 2.16.4