Skip to contentSkip to conversation

readkey: force return from while true

PATCH Superseded Jan Weitzel 3 participants 4 messages Nov 22, 2011 – Nov 24, 2011 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 readkey: force return from while true

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.

---
 lib/readkey.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
lib/readkey.c +2 -0
index a42d1cb..895db82 100644
@@ -67,6 +67,8 @@ int read_key(void)
 				esc[i] = getc();
 				if (esc[i++] == '~')
 					break;
+				if (i == 5)
+					return -1;
 			}
 		}
 		esc[i] = 0;
Signature · 7 lines
1.7.0.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw
Quoted 4 lines · Jan Weitzel

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.

Wow, a shortcut to crash barebox. Applied to master.

Sascha

Quoted 27 lines
---
 lib/readkey.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
lib/readkey.c +2 -0
index a42d1cb..895db82 100644
@@ -67,6 +67,8 @@ int read_key(void)
 				esc[i] = getc();
 				if (esc[i++] == '~')
 					break;
+				if (i == 5)
+					return -1;
 			}
 		}
 		esc[i] = 0;
Signature · 7 lines
1.7.0.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw
Quoted 15 lines · Sascha Hauer
Quoted 4 lines · Jan Weitzel

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.

Wow, a shortcut to crash barebox. Applied to master.

Sascha

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

lib/readkey.c int read_key(void) · line 70

Quoted 9 lines
lib/readkey.c +1 -0
index a42d1cb..895db82 100644
@@ -67,6 +67,8 @@ int read_key(void)
 				esc[i] = getc();
 				if (esc[i++] == '~')
 					break;
+				if (i == 5)

ARRAY_SIZE?

Quoted 8 lines
Quoted 8 lines
lib/readkey.c +1 -0
+					return -1;
 			}
 		}
 		esc[i] = 0;
Signature · 1 line
1.7.0.4
Quoted 6 lines
Quoted 5 lines

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw

PATCH v2 1/1 readkey: force return from while true

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.

---
v2: use ARRAY_SIZE

 lib/readkey.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
lib/readkey.c +2 -0
index a42d1cb..1117c30 100644
@@ -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;
Signature · 7 lines
1.7.0.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox