From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B804C433F5 for ; Thu, 3 Feb 2022 16:47:39 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0679783849; Thu, 3 Feb 2022 17:47:37 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="gaS6Vb3B"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6E51282135; Thu, 3 Feb 2022 17:47:35 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8365F83849 for ; Thu, 3 Feb 2022 17:47:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6AB826155C; Thu, 3 Feb 2022 16:47:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF730C340E8; Thu, 3 Feb 2022 16:47:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643906849; bh=8IR4/xq2HkgJwpPEC4K8F4pRPs8eg3OIRBtG61poSf8=; h=From:To:Cc:Subject:Date:From; b=gaS6Vb3B4xcObFUmze5B6iuQ24nT1SzgGhNWyi2bTYAxG7LPJ3gkywnuAqMbZSmcr flnbG0Ku1YhazlOufsskHFoTi3brm1A5KkjqZCjMkmjNYh0jTA93l76JHFF/IFy7cP KcAPi5wom7gpP5AOfYPRgj5cJHI6dlqCwK8gaAivmjVl4/MmIwFPppXmP7Z1I94zPP hf1BNQkc+HPoCC9QOeZ3aHPol+YoF/W7eB+v2IdsNOKLEIWnxN1m+egSXE4sLldBIc fSpC9fti8R4qZrLBQ4DO7UBbsrXUhE6l7Gf+4f54tC2ejC8/FUne10VWHqWxacpa7z 4Ptv8nAp3azcA== Received: by pali.im (Postfix) id C5616889; Thu, 3 Feb 2022 17:47:26 +0100 (CET) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Stefan Roese , =?UTF-8?q?Marek=20Beh=C3=BAn?= Cc: u-boot@lists.denx.de Subject: [PATCH] tools: kwboot: Fix detection of quit esc sequence Date: Thu, 3 Feb 2022 17:45:20 +0100 Message-Id: <20220203164520.18684-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Quit esc sequence may be also in the middle of the read buffer. Fix the detection for that case. Signed-off-by: Pali Rohár --- tools/kwboot.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tools/kwboot.c b/tools/kwboot.c index 2684f0e75a56..7737188f0d0a 100644 --- a/tools/kwboot.c +++ b/tools/kwboot.c @@ -1183,10 +1183,10 @@ kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate) static int kwboot_term_pipe(int in, int out, const char *quit, int *s) { + char buf[128]; ssize_t nin; - char _buf[128], *buf = _buf; - nin = read(in, buf, sizeof(_buf)); + nin = read(in, buf, sizeof(buf)); if (nin <= 0) return -1; @@ -1194,18 +1194,21 @@ kwboot_term_pipe(int in, int out, const char *quit, int *s) int i; for (i = 0; i < nin; i++) { - if (*buf == quit[*s]) { + if (buf[i] == quit[*s]) { (*s)++; - if (!quit[*s]) - return 0; - buf++; - nin--; + if (!quit[*s]) { + nin = i - *s; + break; + } } else { - if (kwboot_write(out, quit, *s) < 0) + if (*s > i && kwboot_write(out, quit, *s - i) < 0) return -1; *s = 0; } } + + if (i == nin) + nin -= *s; } if (kwboot_write(out, buf, nin) < 0) -- 2.20.1