]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tools: kwboot: Fix quitting terminal
authorPali Rohár <pali@kernel.org>
Fri, 18 Feb 2022 11:24:13 +0000 (12:24 +0100)
committerStefan Roese <sr@denx.de>
Fri, 4 Mar 2022 07:38:05 +0000 (08:38 +0100)
Sometimes kwboot after quitting terminal prints error message:

  terminal: Bad address

This is caused by trying to call write() syscall with count of (size_t)-1
bytes.

When quit sequence is split into more read() calls then number of input
bytes (nin) at the end of cycle can underflow and be negative. Fix it.

Fixes: de7514046ea5 ("tools: kwboot: Fix detection of quit esc sequence")
Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Stefan Roese <sr@denx.de>
tools/kwboot.c

index 68c0ef1f1b07e1303ed2cf164367eae0b9aa78ea..2d2d545d82587d6af0cfb4517405e7157284f9dd 100644 (file)
@@ -1197,7 +1197,7 @@ kwboot_term_pipe(int in, int out, const char *quit, int *s)
                        if (buf[i] == quit[*s]) {
                                (*s)++;
                                if (!quit[*s]) {
-                                       nin = i - *s;
+                                       nin = (i > *s) ? (i - *s) : 0;
                                        break;
                                }
                        } else {
@@ -1208,7 +1208,7 @@ kwboot_term_pipe(int in, int out, const char *quit, int *s)
                }
 
                if (i == nin)
-                       nin -= *s;
+                       nin -= (nin > *s) ? *s : nin;
        }
 
        if (kwboot_write(out, buf, nin) < 0)