Added a timeout on wrong password.

This commit is contained in:
ikolokolnikov committed 2026-10-01 11:47:44 -07:00
1 parent 78c1f81bd5
commit ddf98cf673
2 files changed
+63 -38

No files matched your search

+40 -36
View File
@@ -745,7 +745,7 @@ run_loop(struct arena *arena,
struct timeval tv;
KeySym ksym;
XEvent ev;
unsigned long long rendering_timeout_millis;
unsigned long long rendering_timeout_millis, failure_timeout_millis;
struct dpms_state dpms_state;
struct fonts fonts;
int kbl_brightness;
@@ -775,6 +775,7 @@ run_loop(struct arena *arena,
needs_rendering = 1;
rendering_timeout_millis = millis();
failure_timeout_millis = 0;
while(running) {
fd_set fds;
@@ -851,44 +852,47 @@ run_loop(struct arena *arena,
#endif
}
switch (ksym) {
case XK_Return:
passwd[len] = '\0';
errno = 0;
if (!(inputhash = crypt(passwd, hash)))
fprintf(stderr, "slock: crypt: %s\n", strerror(errno));
else
running = !!strcmp(inputhash, hash);
if (running) {
XBell(dpy, 100);
failure = 1;
} else {
locked = 0;
}
explicit_bzero(&passwd, sizeof(passwd));
len = 0;
break;
case XK_Escape:
explicit_bzero(&passwd, sizeof(passwd));
len = 0;
failure = 0;
break;
case XK_BackSpace:
if (len)
passwd[--len] = '\0';
break;
default:
if (num && !iscntrl((unsigned char)buf[0]) &&
(len + num < sizeof(passwd))) {
memcpy(passwd + len, buf, num);
len += num;
} else if (buf[0] == '\025') { /* ctrl-u clears input */
if(millis() - failure_timeout_millis >= 2000) {
switch (ksym) {
case XK_Return:
passwd[len] = '\0';
errno = 0;
if (!(inputhash = crypt(passwd, hash)))
fprintf(stderr, "slock: crypt: %s\n", strerror(errno));
else
running = !!strcmp(inputhash, hash);
if (running) {
XBell(dpy, 100);
failure = 1;
failure_timeout_millis = millis();
} else {
locked = 0;
}
explicit_bzero(&passwd, sizeof(passwd));
len = 0;
} else {
continue; /* Don't trigger fail screen when pressing control characters */
break;
case XK_Escape:
explicit_bzero(&passwd, sizeof(passwd));
len = 0;
failure = 0;
break;
case XK_BackSpace:
if (len)
passwd[--len] = '\0';
break;
default:
if (num && !iscntrl((unsigned char)buf[0]) &&
(len + num < sizeof(passwd))) {
memcpy(passwd + len, buf, num);
len += num;
} else if (buf[0] == '\025') { /* ctrl-u clears input */
explicit_bzero(&passwd, sizeof(passwd));
len = 0;
} else {
continue; /* Don't trigger fail screen when pressing control characters */
}
break;
}
break;
}
} else if (rr->active && ev.type == rr->evbase + RRScreenChangeNotify) {
rre = (XRRScreenChangeNotifyEvent*)&ev;