[PATCH v2] readkey: force return from while true

Jan Weitzel j.weitzel at phytec.de
Thu Nov 24 05:48:54 EST 2011


If read_key is feeded by STRG + KEY_LEFT you run into the while(1)
loop and corrupt memory through esc array.
Force return if index gets too high.

Signed-off-by: Jan Weitzel <j.weitzel at phytec.de>
---
v2: use ARRAY_SIZE

 lib/readkey.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/readkey.c b/lib/readkey.c
index a42d1cb..1117c30 100644
--- a/lib/readkey.c
+++ b/lib/readkey.c
@@ -67,6 +67,8 @@ int read_key(void)
 				esc[i] = getc();
 				if (esc[i++] == '~')
 					break;
+				if (i == ARRAY_SIZE(esc))
+					return -1;
 			}
 		}
 		esc[i] = 0;
-- 
1.7.0.4




More information about the barebox mailing list