From patchwork Tue Apr 7 15:51:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 1267487 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=mVZeilI2; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48xXCN0rkvz9sR4 for ; Wed, 8 Apr 2020 01:59:12 +1000 (AEST) Received: from localhost ([::1]:49820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLqd4-0007C5-1N for incoming@patchwork.ozlabs.org; Tue, 07 Apr 2020 11:59:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43761) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLqVm-0003pK-Os for qemu-devel@nongnu.org; Tue, 07 Apr 2020 11:51:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLqVl-0004Si-J3 for qemu-devel@nongnu.org; Tue, 07 Apr 2020 11:51:38 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:42130) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jLqVl-0004S6-DL for qemu-devel@nongnu.org; Tue, 07 Apr 2020 11:51:37 -0400 Received: by mail-wr1-x433.google.com with SMTP id h15so4463653wrx.9 for ; Tue, 07 Apr 2020 08:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6B+33TDAfIaOLpicgY8n+ylFencr6qohELifXSSvkE0=; b=mVZeilI2YzyMDuyyFkQnkFrkD8G/vEsr7Vz//hcMCcaxuLqVMrqGslf8CLPepOCTKG 4oo4haNCToi6HUVTMRx8gR505gVrszSGTYnVNax1kX6exw06qD3FBlFHPvvQVqEuDu2v jX8Nmv/L1UjiopQf3IsBAfRNmkTT8g2WWtC/+94fju7p9eyltcQHdxt2UNsmj0Tfhz7m NQaUN4SEE++V1TQAANF4TFi+DSzDPZPjjmpfpBypDFHG3BuTJvevIEbVgoLoqDt0FAkc yuw1uyBC5Bwn3pFRlihUmrXVCPPrGoMGub7bQBox9ROJGgMfOzospe8y40yHzgb2R1tp wwbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6B+33TDAfIaOLpicgY8n+ylFencr6qohELifXSSvkE0=; b=iytMvamwi/r4w5EOVLH1EqqnAWLT5UyXvtXTZbhZ3YWZl84kCg2Sdsvk/Ej5I2iwFt sz2+RmX1027WEnb0mCAeKbJthe+kT7nklbvyPgfRn5ipkhFSwHxrjqTTZEwTDo1hCECb yF0inYAnCN8UBoHIf9ZTvNLkotk0v/HaPdkQc1xzUBfk1T7wgIChcXKwQ5k1Te8rmbF5 CV8KuZl6L0QVTGoAAYEfQMGXCeOm/TXloaMK8CYpzjgyi++c4I81NE0K8lj4Ss4atsp0 wtojqi5I9/TwUMG+dZ3OjXASLT6b4j1v3HtZ7AQy9LGRydyO+mPynYChZ3Zpa0aO2+5W BnLg== X-Gm-Message-State: AGi0PuZwtJOVoZsx9rxSOPFZfRyfZcODPiF7PlWvKFDr8eSHWBOgSC8O KTFOTyXnSmGR3BNHFiywcpwr/BEWzVU= X-Google-Smtp-Source: APiQypI4LrFw1TmdOD7nuzNpDiXH0AsCXatkT8BYpKLOgFl9Cfp760ewJO3QMA6QDeA6I0H2cyezIQ== X-Received: by 2002:adf:ee8b:: with SMTP id b11mr3323659wro.404.1586274696290; Tue, 07 Apr 2020 08:51:36 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id w18sm8881639wrn.55.2020.04.07.08.51.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 08:51:33 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 3F0721FF9A; Tue, 7 Apr 2020 16:51:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 11/13] hw/core: properly terminate loading .hex on EOF record Date: Tue, 7 Apr 2020 16:51:16 +0100 Message-Id: <20200407155118.20139-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200407155118.20139-1-alex.bennee@linaro.org> References: <20200407155118.20139-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::433 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson , =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= , qemu-devel@nongnu.org, Stefan Hajnoczi , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The https://makecode.microbit.org/#editor generates slightly weird .hex files which work fine on a real microbit but causes QEMU to choke. The reason is extraneous data after the EOF record which causes the loader to attempt to write a bigger file than it should to the "rom". According to the HEX file spec an EOF really should be the last thing we process so lets do that. Reported-by: Ursula Bennée Signed-off-by: Alex Bennée Reviewed-by: Stefan Hajnoczi Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20200403191150.863-12-alex.bennee@linaro.org> diff --git a/hw/core/loader.c b/hw/core/loader.c index eeef6da9a1b..8bbb1797a4c 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -1447,6 +1447,7 @@ typedef struct { uint32_t current_rom_index; uint32_t rom_start_address; AddressSpace *as; + bool complete; } HexParser; /* return size or -1 if error */ @@ -1484,6 +1485,7 @@ static int handle_record_type(HexParser *parser) parser->current_rom_index, parser->rom_start_address, parser->as); } + parser->complete = true; return parser->total_size; case EXT_SEG_ADDR_RECORD: case EXT_LINEAR_ADDR_RECORD: @@ -1548,11 +1550,12 @@ static int parse_hex_blob(const char *filename, hwaddr *addr, uint8_t *hex_blob, .bin_buf = g_malloc(hex_blob_size), .start_addr = addr, .as = as, + .complete = false }; rom_transaction_begin(); - for (; hex_blob < end; ++hex_blob) { + for (; hex_blob < end && !parser.complete; ++hex_blob) { switch (*hex_blob) { case '\r': case '\n':