From nobody Thu Nov 6 12:15:35 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541518640104857.6820437350021; Tue, 6 Nov 2018 07:37:20 -0800 (PST) Received: from localhost ([::1]:41739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK3Pq-0000qp-56 for importer@patchew.org; Tue, 06 Nov 2018 10:37:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41678) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK3NF-0006gS-W9 for qemu-devel@nongnu.org; Tue, 06 Nov 2018 10:34:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gK3NB-0003c8-4s for qemu-devel@nongnu.org; Tue, 06 Nov 2018 10:34:37 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:52370) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gK3NA-0002YT-U4 for qemu-devel@nongnu.org; Tue, 06 Nov 2018 10:34:33 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1gK3MC-0007zr-Ki; Tue, 06 Nov 2018 15:33:32 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 6 Nov 2018 15:33:30 +0000 Message-Id: <20181106153330.5139-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH for-3.1] replay: Exit on errors reading from replay log X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Pavel Dovgalyuk , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Currently replay_get_byte() does not check for an error from getc(). Coverity points out (CID 1390622) that this could result in unexpected behaviour (such as looping forever, if we use the replay_get_dword() return value for a loop count). We don't expect reads from the replay log to fail, and if they do there is no way we can continue. So make them fatal errors. Signed-off-by: Peter Maydell Reviewed-by: Pavel Dovgalyuk --- Disclaimer: checked only with "make check". replay/replay-internal.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/replay/replay-internal.c b/replay/replay-internal.c index 1cea1d4dc91..8f87e9b957e 100644 --- a/replay/replay-internal.c +++ b/replay/replay-internal.c @@ -35,6 +35,12 @@ static void replay_write_error(void) } } =20 +static void replay_read_error(void) +{ + error_report("error reading the replay data"); + exit(1); +} + void replay_put_byte(uint8_t byte) { if (replay_file) { @@ -83,7 +89,11 @@ uint8_t replay_get_byte(void) { uint8_t byte =3D 0; if (replay_file) { - byte =3D getc(replay_file); + int r =3D getc(replay_file); + if (r =3D=3D EOF) { + replay_read_error(); + } + byte =3D r; } return byte; } @@ -126,7 +136,7 @@ void replay_get_array(uint8_t *buf, size_t *size) if (replay_file) { *size =3D replay_get_dword(); if (fread(buf, 1, *size, replay_file) !=3D *size) { - error_report("replay read error"); + replay_read_error(); } } } @@ -137,7 +147,7 @@ void replay_get_array_alloc(uint8_t **buf, size_t *size) *size =3D replay_get_dword(); *buf =3D g_malloc(*size); if (fread(*buf, 1, *size, replay_file) !=3D *size) { - error_report("replay read error"); + replay_read_error(); } } } --=20 2.19.1