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 08023C433EF for ; Fri, 4 Feb 2022 05:48:15 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1EC3A83A54; Fri, 4 Feb 2022 06:48:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1643953694; bh=n7TSxfQp7nhJQruQV+i5MEhWgf6MPKIhiP25YPfC7Ww=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=AvTvQt6viGzQFfOcKvOwIwoyuWpJLAcmie/HnDGffw8CX2QQBTCXCX5ay2xrgvgYB 7XyKV/Syb/7UXYBI5F27SjG5HOPbgVpNwDaKI3ozUHQb8O3iUx8I3KTLAWuEc+lR7y hWdW/cWRi6kBh2XT3fAfJP9N/w+zmW3p/xrM07MNSyDxzvVeSrhbkad2l1oOgqpC0k gDQCIL4TSlicv0afUKOaJKkgRTAaGr5SA7BggBuza2xxjiPxjC6Hw2ukP5IHNqLcwY JZK0kvroS1R3mO44Ok3CDJP4x5H461dhZ0kQ3XVElzPMWE1tuoIQe4/jk4G2qzicKZ U7BLWc+umsVyg== Received: by phobos.denx.de (Postfix, from userid 109) id 447FC83A55; Fri, 4 Feb 2022 06:48:12 +0100 (CET) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [91.198.250.253]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9340283A4F for ; Fri, 4 Feb 2022 06:48:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp1.mailbox.org (unknown [91.198.250.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4Jql213gpbz9sqw; Fri, 4 Feb 2022 06:48:09 +0100 (CET) Message-ID: Date: Fri, 4 Feb 2022 06:48:02 +0100 MIME-Version: 1.0 Subject: Re: [PATCH] tools: kwboot: Fix detection of quit esc sequence Content-Language: en-US To: =?UTF-8?Q?Pali_Roh=c3=a1r?= , =?UTF-8?Q?Marek_Beh=c3=ban?= Cc: u-boot@lists.denx.de References: <20220203164520.18684-1-pali@kernel.org> From: Stefan Roese In-Reply-To: <20220203164520.18684-1-pali@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed 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 On 2/3/22 17:45, Pali Rohár wrote: > 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 Reviewed-by: Stefan Roese Thanks, Stefan > --- > 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) Viele Grüße, Stefan Roese -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de