9
0
Fork 0

password: fixed underflow on <backspace>

due to missing/misplaced boundary check, deleting characters could
underflow the password buffer.

Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Enrico Scholz 2012-12-04 13:04:25 +01:00 committed by Sascha Hauer
parent 6f70eea9ca
commit e7111ebd28
1 changed files with 8 additions and 5 deletions

View File

@ -66,11 +66,14 @@ int password(unsigned char *passwd, size_t length, int flags, int timeout)
case CTL_CH('h'):
case KEY_DEL7:
case KEY_DEL:
if (flags & STAR && pos > 0)
puts("\b \b");
*buf = '\0';
buf--;
pos--;
if (pos > 0) {
if (flags & STAR)
puts("\b \b");
*buf = '\0';
buf--;
pos--;
}
continue;
default:
if (pos < length - 1) {