All of lore.kernel.org
 help / color / mirror / Atom feed
From: matthias.bgg at kernel.org <matthias.bgg@kernel.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/2] efi_loader: Fix possible starving in efi_cin_read_key
Date: Tue,  5 Mar 2019 12:50:19 +0100	[thread overview]
Message-ID: <20190305115019.3581-2-matthias.bgg@kernel.org> (raw)
In-Reply-To: <20190305115019.3581-1-matthias.bgg@kernel.org>

From: Matthias Brugger <mbrugger@suse.com>

The function efi_cin_read_key can be affected by a loss of
a character which will make u-boot to wait forever.
Fix this by calling term_get_char instead.

Signed-off-by: Matthias Brugger <mbrugger@suse.com>
---

Changes in v2: None

 lib/efi_loader/efi_console.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c
index 1133674faf..558aaed109 100644
--- a/lib/efi_loader/efi_console.c
+++ b/lib/efi_loader/efi_console.c
@@ -493,13 +493,14 @@ static int analyze_modifiers(struct efi_key_state *key_state)
 {
 	int c, mod = 0, ret = 0;
 
-	c = getc();
+	if (!term_get_char(&c))
+		goto out;
 
 	if (c != ';') {
 		ret = c;
 		if (c == '~')
 			goto out;
-		c = getc();
+		term_get_char(&c);
 	}
 	for (;;) {
 		switch (c) {
@@ -508,7 +509,7 @@ static int analyze_modifiers(struct efi_key_state *key_state)
 			mod += c - '0';
 		/* fall through */
 		case ';':
-			c = getc();
+			term_get_char(&c);
 			break;
 		default:
 			goto out;
@@ -551,7 +552,9 @@ static efi_status_t efi_cin_read_key(struct efi_key_data *key)
 		 * Xterm Control Sequences
 		 * https://www.xfree86.org/4.8.0/ctlseqs.html
 		 */
-		ch = getc();
+		if (!term_get_char(&ch))
+			return EFI_NOT_READY;
+
 		switch (ch) {
 		case cESC: /* ESC */
 			pressed_key.scan_code = 23;
@@ -561,12 +564,15 @@ static efi_status_t efi_cin_read_key(struct efi_key_data *key)
 			/* consider modifiers */
 			if (ch < 'P') {
 				set_shift_mask(ch - '0', &key->key_state);
-				ch = getc();
+				if (!term_get_char(&ch))
+					return EFI_NOT_READY;
 			}
 			pressed_key.scan_code = ch - 'P' + 11;
 			break;
 		case '[':
-			ch = getc();
+			if (!term_get_char(&ch))
+				return EFI_NOT_READY;
+
 			switch (ch) {
 			case 'A'...'D': /* up, down right, left */
 				pressed_key.scan_code = ch - 'A' + 1;
-- 
2.20.1

  reply	other threads:[~2019-03-05 11:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-05 11:50 [U-Boot] [PATCH v2 1/2] efi_loader: Fix serial console size detection matthias.bgg at kernel.org
2019-03-05 11:50 ` matthias.bgg at kernel.org [this message]
2019-03-05 18:44   ` [U-Boot] [PATCH v2 2/2] efi_loader: Fix possible starving in efi_cin_read_key Heinrich Schuchardt
2019-03-05 18:03 ` [U-Boot] [PATCH v2 1/2] efi_loader: Fix serial console size detection Heinrich Schuchardt
2019-03-05 18:43 ` Heinrich Schuchardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190305115019.3581-2-matthias.bgg@kernel.org \
    --to=matthias.bgg@kernel.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.