From patchwork Mon Aug 1 06:49:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 107682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5068EB70B2 for ; Mon, 1 Aug 2011 16:51:39 +1000 (EST) Received: from localhost ([::1]:58336 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QnmLa-0001F2-TU for incoming@patchwork.ozlabs.org; Mon, 01 Aug 2011 02:51:30 -0400 Received: from eggs.gnu.org ([140.186.70.92]:49956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QnmLM-0000dj-CQ for qemu-devel@nongnu.org; Mon, 01 Aug 2011 02:51:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QnmLI-0000kN-3b for qemu-devel@nongnu.org; Mon, 01 Aug 2011 02:51:16 -0400 Received: from ozlabs.org ([203.10.76.45]:48614) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QnmLH-0000k9-P7; Mon, 01 Aug 2011 02:51:12 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 8EF56B70BB; Mon, 1 Aug 2011 16:51:07 +1000 (EST) From: David Gibson To: qemu-devel@nongnu.org Date: Mon, 1 Aug 2011 16:49:59 +1000 Message-Id: <1312181399-29841-1-git-send-email-david@gibson.dropbear.id.au> X-Mailer: git-send-email 1.7.5.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 203.10.76.45 Cc: qemu-trivial@nongnu.org Subject: [Qemu-devel] [PATCH] Check fread() results to avoid gcc 4.6 warnings X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When compiling with gcc 4.6, some code in fw_cfg.c complains that fop_ret is assigned but not used (which is true). However, it looks like the meaningless assignments to fop_ret were done to suppress other gcc warnings due to the fact that fread() is labelled as warn_unused_result in glibc. This patch avoids both errors, by actually checking the fread() result code and dropping out with an error message if it fails. Signed-off-by: David Gibson Reviewed-by: Stefan Hajnoczi Tested-by: Stefan Berger --- hw/fw_cfg.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c index a29db90..e4847b7 100644 --- a/hw/fw_cfg.c +++ b/hw/fw_cfg.c @@ -87,6 +87,13 @@ static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep) /* check magic ID */ fseek(fp, 0L, SEEK_SET); fop_ret = fread(buf, 1, 2, fp); + if (fop_ret != 2) { + error_report("Could not read header from '%s': %s", + filename, strerror(errno)); + fclose(fp); + fp = NULL; + return fp; + } filehead_value = (buf[0] + (buf[1] << 8)) & 0xffff; if (filehead_value == 0xd8ff) { file_type = JPG_FILE; @@ -181,6 +188,12 @@ static void fw_cfg_bootsplash(FWCfgState *s) boot_splash_filedata_size = file_size; fseek(fp, 0L, SEEK_SET); fop_ret = fread(boot_splash_filedata, 1, file_size, fp); + if (fop_ret != file_size) { + error_report("failed to read data from '%s'.", + boot_splash_filename); + fclose(fp); + return; + } fclose(fp); /* insert data */ if (file_type == JPG_FILE) {