From nobody Mon Feb 9 15:29:16 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1766644520405911.4000947480138; Wed, 24 Dec 2025 22:35:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vYew9-00065E-Iq; Thu, 25 Dec 2025 01:35:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vYew7-00064l-8F for qemu-devel@nongnu.org; Thu, 25 Dec 2025 01:34:59 -0500 Received: from smtp-pop-umt-1.cecloud.com ([1.203.97.246] helo=smtp.cecloud.com) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vYew4-0003N0-3U for qemu-devel@nongnu.org; Thu, 25 Dec 2025 01:34:59 -0500 Received: from localhost (localhost [127.0.0.1]) by smtp.cecloud.com (Postfix) with ESMTP id 1D9027C0119; Thu, 25 Dec 2025 14:34:38 +0800 (CST) Received: from localhost.localdomain (unknown [111.48.69.245]) by smtp.cecloud.com (postfix) whith ESMTP id P3424602T281460011430256S1766644474672507_; Thu, 25 Dec 2025 14:34:37 +0800 (CST) X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-SKE-CHECKED: 1 X-ANTISPAM-LEVEL: 2 X-IP-DOMAINF: 1 X-RL-SENDER: luzhipeng@cestc.cn X-SENDER: luzhipeng@cestc.cn X-LOGIN-NAME: luzhipeng@cestc.cn X-FST-TO: qemu-devel@nongnu.org X-RCPT-COUNT: 4 X-LOCAL-RCPT-COUNT: 1 X-MUTI-DOMAIN-COUNT: 0 X-SENDER-IP: 111.48.69.245 X-ATTACHMENT-NUM: 0 X-UNIQUE-TAG: X-System-Flag: 0 From: luzhipeng To: qemu-devel@nongnu.org Cc: =?UTF-8?q?=27Marc-Andr=C3=A9=20Lureau=27?= , Paolo Bonzini , luzhipeng Subject: [PATCH] chardev/pty: fix incorrect return value in char_pty_chr_write Date: Thu, 25 Dec 2025 14:34:12 +0800 Message-ID: <20251225063412.572-1-luzhipeng@cestc.cn> X-Mailer: git-send-email 2.45.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=1.203.97.246; envelope-from=luzhipeng@cestc.cn; helo=smtp.cecloud.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1766644525286158500 Content-Type: text/plain; charset="utf-8" In char_pty_chr_write(), when the PTY is not connected (s->connected =3D=3D false), the function attempts a non-blocking poll to check if the fd is=20 writable. However, even if the fd is not writable or if io_channel_send() fails the function unconditionally returns 'len', falsely indicating that all data was successfully written. Signed-off-by: luzhipeng --- chardev/char-pty.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chardev/char-pty.c b/chardev/char-pty.c index 652b0bd9e7..37a20d5f4b 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -124,11 +124,15 @@ static int char_pty_chr_write(Chardev *chr, const uin= t8_t *buf, int len) pfd.revents =3D 0; rc =3D RETRY_ON_EINTR(g_poll(&pfd, 1, 0)); g_assert(rc >=3D 0); + if ((pfd.revents & G_IO_HUP) || !(pfd.revents & G_IO_OUT)) { + return 0; + } if (!(pfd.revents & G_IO_HUP) && (pfd.revents & G_IO_OUT)) { return io_channel_send(s->ioc, buf, len); } =20 - return len; + int ret =3D io_channel_send(s->ioc, buf, len); + return ret; } =20 static GSource *pty_chr_add_watch(Chardev *chr, GIOCondition cond) --=20 2.45.1.windows.1