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: 1661957 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ZQL0/8xi; dkim-atps=neutral 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=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LvMsF3G4xz9s07 for ; Fri, 29 Jul 2022 19:38:39 +1000 (AEST) Received: from localhost ([::1]:46944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHMS3-0005rz-7y for incoming@patchwork.ozlabs.org; Fri, 29 Jul 2022 05:38:35 -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-Google-Smtp-Source: AGRyM1uGDj9UjMnUr/p/DTE2SweG2zO64jbT/zG9luVuqIeqY4NNvnIj0Jh29k67/5WgCOs6SByzkg== 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+incoming=patchwork.ozlabs.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); }