From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aR8t5-0008Lw-99 for qemu-devel@nongnu.org; Wed, 03 Feb 2016 20:39:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aR8t4-0007HZ-DW for qemu-devel@nongnu.org; Wed, 03 Feb 2016 20:39:11 -0500 Date: Thu, 4 Feb 2016 09:38:58 +0800 From: Fam Zheng Message-ID: <20160204013858.GA5187@ad.usersys.redhat.com> References: <1454542737-14742-1-git-send-email-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1454542737-14742-1-git-send-email-jsnow@redhat.com> Subject: Re: [Qemu-devel] [PATCH] qemu-img: initialize MapEntry object List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: John Snow Cc: kwolf@redhat.com, qemu-devel@nongnu.org, qemu-block@nongnu.org On Wed, 02/03 18:38, John Snow wrote: > Commit 16b0d555 introduced an issue where we are not initializing > has_filename for the 'next' MapEntry object, which leads to interesting > errors in Valgrind and Clang -fsanitize=undefined both. > > Zero the stack object at allocation AND make sure the utility to > populate the fields properly marks has_filename as false if applicable. > > Signed-off-by: John Snow > --- > qemu-img.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/qemu-img.c b/qemu-img.c > index f121980..5a85178 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -2231,6 +2231,9 @@ static int get_block_status(BlockDriverState *bs, int64_t sector_num, > if (file && e->has_offset) { > e->has_filename = true; > e->filename = file->filename; > + } else { > + e->has_filename = false; > + e->filename = NULL; > } > return 0; > } > @@ -2264,7 +2267,7 @@ static int img_map(int argc, char **argv) > BlockDriverState *bs; > const char *filename, *fmt, *output; > int64_t length; > - MapEntry curr = { .length = 0 }, next; > + MapEntry curr = { .length = 0 }, next = { .length = 0 }; > int ret = 0; > > fmt = NULL; > -- > 2.4.3 > Reviewed-by: Fam Zheng