diff options
author | 2016-04-09 18:15:50 -0400 | |
---|---|---|
committer | 2016-04-09 18:15:50 -0400 | |
commit | 3b5a8cb40d4ab07aa9a72ba87660e4b9801afa21 (patch) | |
tree | a0640556c2738dbb8cd3236024e3a0296fdf66e5 /swaylock | |
parent | Merge pull request #579 from mikkeloscar/new_view-geometry (diff) | |
parent | swaylock: Handle possible fail on password realloc (diff) | |
download | sway-3b5a8cb40d4ab07aa9a72ba87660e4b9801afa21.tar.gz sway-3b5a8cb40d4ab07aa9a72ba87660e4b9801afa21.tar.zst sway-3b5a8cb40d4ab07aa9a72ba87660e4b9801afa21.zip |
Merge pull request #580 from mikkeloscar/handle-realloc-fail
swaylock: Handle possible fail on password realloc
Diffstat (limited to 'swaylock')
-rw-r--r-- | swaylock/main.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index 57fe0321..1885b511 100644 --- a/swaylock/main.c +++ b/swaylock/main.c | |||
@@ -113,6 +113,8 @@ bool verify_password() { | |||
113 | 113 | ||
114 | void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) { | 114 | void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) { |
115 | int redraw_screen = 0; | 115 | int redraw_screen = 0; |
116 | char *password_realloc; | ||
117 | |||
116 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { | 118 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
117 | switch (sym) { | 119 | switch (sym) { |
118 | case XKB_KEY_Return: | 120 | case XKB_KEY_Return: |
@@ -129,6 +131,7 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod | |||
129 | redraw_screen = 1; | 131 | redraw_screen = 1; |
130 | 132 | ||
131 | password_size = 1024; | 133 | password_size = 1024; |
134 | free(password); | ||
132 | password = malloc(password_size); | 135 | password = malloc(password_size); |
133 | password[0] = '\0'; | 136 | password[0] = '\0'; |
134 | break; | 137 | break; |
@@ -149,7 +152,17 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod | |||
149 | int i = strlen(password); | 152 | int i = strlen(password); |
150 | if (i + 1 == password_size) { | 153 | if (i + 1 == password_size) { |
151 | password_size += 1024; | 154 | password_size += 1024; |
152 | password = realloc(password, password_size); | 155 | password_realloc = realloc(password, password_size); |
156 | // reset password if realloc fails. | ||
157 | if (password_realloc == NULL) { | ||
158 | password_size = 1024; | ||
159 | free(password); | ||
160 | password = malloc(password_size); | ||
161 | password[0] = '\0'; | ||
162 | break; | ||
163 | } else { | ||
164 | password = password_realloc; | ||
165 | } | ||
153 | } | 166 | } |
154 | password[i] = (char)codepoint; | 167 | password[i] = (char)codepoint; |
155 | password[i + 1] = '\0'; | 168 | password[i + 1] = '\0'; |
@@ -305,7 +318,7 @@ int main(int argc, char **argv) { | |||
305 | break; | 318 | break; |
306 | } | 319 | } |
307 | switch (c) { | 320 | switch (c) { |
308 | case 'c': | 321 | case 'c': |
309 | { | 322 | { |
310 | int colorlen = strlen(optarg); | 323 | int colorlen = strlen(optarg); |
311 | if (colorlen < 6 || colorlen == 7 || colorlen > 8) { | 324 | if (colorlen < 6 || colorlen == 7 || colorlen > 8) { |