* [PATCH] tools: kwboot: Fix detection of quit esc sequence
@ 2022-02-03 16:45 Pali Rohár
2022-02-04 5:48 ` Stefan Roese
2022-02-10 8:18 ` Stefan Roese
0 siblings, 2 replies; 3+ messages in thread
From: Pali Rohár @ 2022-02-03 16:45 UTC (permalink / raw)
To: Stefan Roese, Marek Behún; +Cc: u-boot
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 <pali@kernel.org>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tools: kwboot: Fix detection of quit esc sequence
2022-02-03 16:45 [PATCH] tools: kwboot: Fix detection of quit esc sequence Pali Rohár
@ 2022-02-04 5:48 ` Stefan Roese
2022-02-10 8:18 ` Stefan Roese
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Roese @ 2022-02-04 5:48 UTC (permalink / raw)
To: Pali Rohár, Marek Behún; +Cc: u-boot
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 <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tools: kwboot: Fix detection of quit esc sequence
2022-02-03 16:45 [PATCH] tools: kwboot: Fix detection of quit esc sequence Pali Rohár
2022-02-04 5:48 ` Stefan Roese
@ 2022-02-10 8:18 ` Stefan Roese
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Roese @ 2022-02-10 8:18 UTC (permalink / raw)
To: Pali Rohár, Marek Behún; +Cc: u-boot
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 <pali@kernel.org>
Applied to u-boot-marvell/master
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-02-10 8:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03 16:45 [PATCH] tools: kwboot: Fix detection of quit esc sequence Pali Rohár
2022-02-04 5:48 ` Stefan Roese
2022-02-10 8:18 ` Stefan Roese
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.