mirror of
https://github.com/swaywm/sway.git
synced 2024-12-29 00:16:22 +01:00
swaylock: Handle possible fail on password realloc
This commit is contained in:
parent
a71ca65d88
commit
f8bb487ddb
1 changed files with 15 additions and 2 deletions
|
@ -113,6 +113,8 @@ bool verify_password() {
|
||||||
|
|
||||||
void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) {
|
void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) {
|
||||||
int redraw_screen = 0;
|
int redraw_screen = 0;
|
||||||
|
char *password_realloc;
|
||||||
|
|
||||||
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||||
switch (sym) {
|
switch (sym) {
|
||||||
case XKB_KEY_Return:
|
case XKB_KEY_Return:
|
||||||
|
@ -129,6 +131,7 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod
|
||||||
redraw_screen = 1;
|
redraw_screen = 1;
|
||||||
|
|
||||||
password_size = 1024;
|
password_size = 1024;
|
||||||
|
free(password);
|
||||||
password = malloc(password_size);
|
password = malloc(password_size);
|
||||||
password[0] = '\0';
|
password[0] = '\0';
|
||||||
break;
|
break;
|
||||||
|
@ -149,7 +152,17 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod
|
||||||
int i = strlen(password);
|
int i = strlen(password);
|
||||||
if (i + 1 == password_size) {
|
if (i + 1 == password_size) {
|
||||||
password_size += 1024;
|
password_size += 1024;
|
||||||
password = realloc(password, password_size);
|
password_realloc = realloc(password, password_size);
|
||||||
|
// reset password if realloc fails.
|
||||||
|
if (password_realloc == NULL) {
|
||||||
|
password_size = 1024;
|
||||||
|
free(password);
|
||||||
|
password = malloc(password_size);
|
||||||
|
password[0] = '\0';
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
password = password_realloc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
password[i] = (char)codepoint;
|
password[i] = (char)codepoint;
|
||||||
password[i + 1] = '\0';
|
password[i + 1] = '\0';
|
||||||
|
@ -305,7 +318,7 @@ int main(int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
{
|
{
|
||||||
int colorlen = strlen(optarg);
|
int colorlen = strlen(optarg);
|
||||||
if (colorlen < 6 || colorlen == 7 || colorlen > 8) {
|
if (colorlen < 6 || colorlen == 7 || colorlen > 8) {
|
||||||
|
|
Loading…
Reference in a new issue