]> git.baikalelectronics.ru Git - uboot.git/commitdiff
tools: kwboot: Fix buffer overflow in kwboot_terminal()
authorMarek Behún <marek.behun@nic.cz>
Fri, 24 Sep 2021 21:06:39 +0000 (23:06 +0200)
committerStefan Roese <sr@denx.de>
Fri, 1 Oct 2021 09:07:13 +0000 (11:07 +0200)
The `in` variable is set to -1 in kwboot_terminal() if stdin is not a
tty. In this case we should not look whether -1 is set in fd_set, for it
can lead to a buffer overflow, which can be reproduced with
  echo "xyz" | ./tools/kwboot -t /dev/ttyUSB0

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
tools/kwboot.c

index 7feeaa45a22da97fed413bdf8a67862708f8d849..e6e99849a798f82778a9896bbda0e0869985042c 100644 (file)
@@ -552,7 +552,7 @@ kwboot_terminal(int tty)
                                break;
                }
 
-               if (FD_ISSET(in, &rfds)) {
+               if (in >= 0 && FD_ISSET(in, &rfds)) {
                        rc = kwboot_term_pipe(in, tty, quit, &s);
                        if (rc)
                                break;