From patchwork Fri Jul 29 09:19:36 2022 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: 594355 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1186906maz; Fri, 29 Jul 2022 02:39:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sjX/rOUCIgcRBDXbkiG6njDq8Uj8k+LmTCX9mn+T4ahxySYGQka2EaBI4GjVbMqz/0cz08 X-Received: by 2002:a05:620a:2984:b0:6b5:fe1c:375e with SMTP id r4-20020a05620a298400b006b5fe1c375emr2018867qkp.494.1659087563100; Fri, 29 Jul 2022 02:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659087563; cv=none; d=google.com; s=arc-20160816; b=jMvqj6FxLcxCRBuRu7Q+Mb4qoz7JeyrEXOr/49/HfpZOAHAr5cFQZxhzk8JdOtUlAW CnyTZ0Rq1ErSUIGEkFy8AZ0q8dN4KvwgDm6+QI0LgKDZZN/67ikKE5wla8njS4iQLMY+ 1+wJTf9n28E9O/i0uVHb8hR7Slx6Neazx5zB/6s60GD8MjSEhtxO5P17Ge4D8Tm9q+fB Bi8Xnlji7wtw/tXlF+xkaeFVy+GuypT27Fgd9jn6xmF/e00BkCmqJjqKDxzIV15sODiS 1y30Y9bKaNSFLz4SoNyR5W79cUVcJx/oOAjqYizxRBHFXwPJo6Yx2fCAdMcDv4Eqz/Q2 s3/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CI2B5ZVJoTazFK681pZ94MwKHGJqZMA5i4E0K05POYU=; b=0Ss1UVq+c/JoHECm23EtqVtBPmy4j3SeEBRNmVTDW48vXqzWYTMhoHTVlfc3Uw1mEG 6rWWHEuuX2/7IgX0Mk4kH2jfPHHtt6G0n8N+8SuW7VhU78EHX4Ha92zkBtLPjpiTagYX HU8M35q7L3GTN5c3iXiUhQtkxSGpqCMX8KvQG1i1BQnbQWYGpkzF3cd2Tenzz4FfwO+T X5GEcKpEqDGu+/aOY6svmiTB2o/zI6tjue8LkKcxCsZUPrVnvYwPBx/cA0PYR7G2MAd2 hkepz1LtH6ga3d1pHflszmH420yx+4T7un0uk8dPAqNcAITRLjkUcP7HzuCIpn4qU5sI mlNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ZQL0/8xi"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id kk14-20020a056214508e00b004726aac5926si1667941qvb.310.2022.07.29.02.39.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 Jul 2022 02:39:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ZQL0/8xi"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHMSo-0005rz-MD for patch@linaro.org; Fri, 29 Jul 2022 05:39:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHMA4-0002Vr-I6 for qemu-devel@nongnu.org; Fri, 29 Jul 2022 05:20:02 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:39701) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHMA2-0005sy-Tn for qemu-devel@nongnu.org; Fri, 29 Jul 2022 05:20:00 -0400 Received: by mail-wm1-x334.google.com with SMTP id i10-20020a1c3b0a000000b003a2fa488efdso1600164wma.4 for ; Fri, 29 Jul 2022 02:19:56 -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=CI2B5ZVJoTazFK681pZ94MwKHGJqZMA5i4E0K05POYU=; b=ZQL0/8xif3s7kPiKkVlNFFqMfrdbHCXSAoTEkrztckLNH7aLSr5xqcQbpmsTp/URDJ j3BSES1pKnt7gu9RbbaHA+W+HEYRJAyI5O5sXaO/xCkcMnzlpm82EQrCc6Qou/JKuJDX 5VHUty0AYW0hlFq7tKxxF/+Z0W1L8INwOLDXly5jxKR5akv6YNKjjyEU3JuAdmEOUDe1 PtsncnqXRvIujqSsTruLwjqmHyd0ztzchA4LPfFQRNjklkCtfojhUmIvPyl/9lVO1m7n d1LWgQT6DmPHdvF5jDzcwg9SQIy4d2LZXnGaFcG/dvrbvz61XyFlL3L21jOz7uQ61IFd WAjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CI2B5ZVJoTazFK681pZ94MwKHGJqZMA5i4E0K05POYU=; b=zlkX1Jm3eADp3jbno1eYglDhgACIc0md/CrM1N1AFy0czEHlK2QS217SirUo82MVP1 /7ON1ECZ/Sh6bGaP0psEZESxJg3jz3W+kybs6IozWjgt6N4Pg6PZpt1iW7FIqsDqxIjm odthmTdY6muSly13YIj2tjOe5k/VC2WD1B5qgMkipvn95P5gyNPwNeD9HUCJtX5HHcsY nw2j7F+iPmbXNC++GuPdLCZRLZHjJgeYF6Hx+j1uIrxzfyBiEio5JwkOUZRnPLXU2q6f G2p29l6oWoG2HRt96EdhVID8qBB/WeW5UQGW0HwQikzHccOq8huC/HpQCmYcVz+l+z5F 32Hw== X-Gm-Message-State: AJIora/n0+kGGSzfSy40iE3dJ1DcWZP1Zyq4S2k02SC78bzAKjBJw8MS Dmlpwd9W2044hk8t0MJx4nJQNw== X-Received: by 2002:a05:600c:4e88:b0:3a3:1bdc:cb72 with SMTP id f8-20020a05600c4e8800b003a31bdccb72mr2188940wmq.59.1659086395914; Fri, 29 Jul 2022 02:19:55 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id o5-20020a05600c510500b003a2d6f26babsm4043065wms.3.2022.07.29.02.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 02:19:52 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 5CB321FFBE; Fri, 29 Jul 2022 10:19:44 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org, richard.henderson@linaro.org Cc: qemu-devel@nongnu.org, =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_M?= =?utf-8?q?athieu-Daud=C3=A9?= Subject: [PULL 06/13] semihosting: Don't return negative values on qemu_semihosting_console_write() failure Date: Fri, 29 Jul 2022 10:19:36 +0100 Message-Id: <20220729091943.2152410-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220729091943.2152410-1-alex.bennee@linaro.org> References: <20220729091943.2152410-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell The documentation comment for qemu_semihosting_console_write() says * Returns: number of bytes written -- this should only ever be short * on some sort of i/o error. and the callsites rely on this. However, the implementation code path which sends console output to a chardev doesn't honour this, and will return negative values on error. Bring it into line with the other implementation codepaths and the documentation, so that it returns 0 on error. Spotted by Coverity, because console_write() passes the return value to unlock_user(), which doesn't accept a negative length. Resolves: Coverity CID 1490288 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-Id: <20220719121110.225657-2-peter.maydell@linaro.org> Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20220725140520.515340-7-alex.bennee@linaro.org> diff --git a/semihosting/console.c b/semihosting/console.c index 5b1ec0a1c3..0f976fe8cb 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -111,7 +111,8 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) int qemu_semihosting_console_write(void *buf, int len) { if (console.chr) { - return qemu_chr_write_all(console.chr, (uint8_t *)buf, len); + int r = qemu_chr_write_all(console.chr, (uint8_t *)buf, len); + return r < 0 ? 0 : r; } else { return fwrite(buf, 1, len, stderr); }