summaryrefslogtreecommitdiff
path: root/apps/plugins/keybox.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/keybox.c')
-rw-r--r--apps/plugins/keybox.c62
1 files changed, 32 insertions, 30 deletions
diff --git a/apps/plugins/keybox.c b/apps/plugins/keybox.c
index d3b03f28a7..389299d580 100644
--- a/apps/plugins/keybox.c
+++ b/apps/plugins/keybox.c
@@ -5,7 +5,7 @@
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id:$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2008 Nils Wallménius 10 * Copyright (C) 2008 Nils Wallménius
11 * 11 *
@@ -111,13 +111,13 @@ MENUITEM_RETURNVALUE(context_add_entry, "Add entry", 0,
111 NULL, Icon_NOICON); 111 NULL, Icon_NOICON);
112MENUITEM_RETURNVALUE(context_edit_title, "Edit title", 1, 112MENUITEM_RETURNVALUE(context_edit_title, "Edit title", 1,
113 &context_item_cb, Icon_NOICON); 113 &context_item_cb, Icon_NOICON);
114MENUITEM_RETURNVALUE(context_edit_name, "Edit user name", 1, 114MENUITEM_RETURNVALUE(context_edit_name, "Edit user name", 2,
115 &context_item_cb, Icon_NOICON); 115 &context_item_cb, Icon_NOICON);
116MENUITEM_RETURNVALUE(context_edit_password, "Edit password", 2, 116MENUITEM_RETURNVALUE(context_edit_password, "Edit password", 3,
117 &context_item_cb, Icon_NOICON); 117 &context_item_cb, Icon_NOICON);
118MENUITEM_RETURNVALUE(context_delete_entry, "Delete entry", 3, 118MENUITEM_RETURNVALUE(context_delete_entry, "Delete entry", 4,
119 &context_item_cb, Icon_NOICON); 119 &context_item_cb, Icon_NOICON);
120MENUITEM_RETURNVALUE(context_debug, "debug", 4, 120MENUITEM_RETURNVALUE(context_debug, "debug", 5,
121 &context_item_cb, Icon_NOICON); 121 &context_item_cb, Icon_NOICON);
122 122
123MAKE_MENU(context_m, "Context menu", 123MAKE_MENU(context_m, "Context menu",
@@ -144,9 +144,12 @@ static char * kb_list_cb(int selected_item, void *data,
144 struct pw_entry *entry = pw_list.first.next; 144 struct pw_entry *entry = pw_list.first.next;
145 for (i = 0; i < selected_item; i++) 145 for (i = 0; i < selected_item; i++)
146 { 146 {
147 if (entry->next) 147 if (entry)
148 entry = entry->next; 148 entry = entry->next;
149 } 149 }
150 if (!entry)
151 return NULL;
152
150 rb->snprintf(buffer, buffer_len, "%s", entry->title); 153 rb->snprintf(buffer, buffer_len, "%s", entry->title);
151 154
152 return buffer; 155 return buffer;
@@ -162,21 +165,20 @@ static void init_ll(void)
162static void delete_entry(int selected_item) 165static void delete_entry(int selected_item)
163{ 166{
164 int i; 167 int i;
165 struct pw_entry *entry = pw_list.first.next; 168 struct pw_entry *entry = &pw_list.first;
166 struct pw_entry *entry2; 169 struct pw_entry *entry2;
167 170
168 /* find the entry before the one to delete */ 171 /* find the entry before the one to delete */
169 for (i = 0; i < selected_item - 1; i++) 172 for (i = 0; i < selected_item; i++)
170 { 173 {
171 if (entry->next) 174 if (entry->next)
172 entry = entry->next; 175 entry = entry->next;
173 } 176 }
174 if (entry->next) 177 entry2 = entry->next;
175 entry2 = entry->next; 178 if (!entry2)
176 else
177 return; 179 return;
178 if (entry2->next) 180
179 entry->next = entry2->next; 181 entry->next = entry2->next;
180 182
181 entry2->used = false; 183 entry2->used = false;
182 entry2->name[0] = '\0'; 184 entry2->name[0] = '\0';
@@ -201,10 +203,13 @@ static void add_entry(int selected_item)
201 } 203 }
202 204
203 rb->splash(HZ, "Enter title"); 205 rb->splash(HZ, "Enter title");
206 pw_list.entries[i].title[0] = '\0';
204 rb->kbd_input(pw_list.entries[i].title, FIELD_LEN); 207 rb->kbd_input(pw_list.entries[i].title, FIELD_LEN);
205 rb->splash(HZ, "Enter name"); 208 rb->splash(HZ, "Enter name");
209 pw_list.entries[i].name[0] = '\0';
206 rb->kbd_input(pw_list.entries[i].name, FIELD_LEN); 210 rb->kbd_input(pw_list.entries[i].name, FIELD_LEN);
207 rb->splash(HZ, "Enter password"); 211 rb->splash(HZ, "Enter password");
212 pw_list.entries[i].password[0] = '\0';
208 rb->kbd_input(pw_list.entries[i].password, FIELD_LEN); 213 rb->kbd_input(pw_list.entries[i].password, FIELD_LEN);
209 214
210 for (j = 0; j < selected_item; j++) 215 for (j = 0; j < selected_item; j++)
@@ -392,7 +397,7 @@ static void encrypt_buffer(char *buf, size_t size, uint32_t *key)
392static int parse_buffer(void) 397static int parse_buffer(void)
393{ 398{
394 int i; 399 int i;
395 intptr_t len; 400 int len;
396 struct pw_entry *entry = pw_list.first.next; 401 struct pw_entry *entry = pw_list.first.next;
397 char *start, *end; 402 char *start, *end;
398 start = &buffer[HEADER_LEN]; 403 start = &buffer[HEADER_LEN];
@@ -408,40 +413,36 @@ static int parse_buffer(void)
408 return -1; 413 return -1;
409 } 414 }
410 415
411 for (i=0; i < MAX_ENTRIES; i++) 416 for (i = 0; i < MAX_ENTRIES; i++)
412 { 417 {
413 end = rb->strchr(start, '\0'); /* find eol */ 418 end = rb->strchr(start, '\0'); /* find eol */
414 len = (intptr_t)end - (intptr_t)&buffer[HEADER_LEN]; 419 len = end - &buffer[HEADER_LEN];
415 if ((len > bytes_read + HEADER_LEN) 420 if ((len > bytes_read + HEADER_LEN) || start == end)
416 || (intptr_t)start == (intptr_t)end)
417 { 421 {
418 break; 422 break;
419 } 423 }
420 424
421 rb->strncpy(entry->title, start, 425 rb->strncpy(entry->title, start, FIELD_LEN);
422 MIN((intptr_t)end - (intptr_t)start, FIELD_LEN)); 426 start = end + 1;
423 start = end +1;
424 427
425 end = rb->strchr(start, '\0'); /* find eol */ 428 end = rb->strchr(start, '\0'); /* find eol */
426 len = (intptr_t)end - (intptr_t)&buffer[HEADER_LEN]; 429 len = end - &buffer[HEADER_LEN];
427 if (len > bytes_read + HEADER_LEN) 430 if (len > bytes_read + HEADER_LEN)
428 { 431 {
429 break; 432 break;
430 } 433 }
431 434
432 rb->strncpy(entry->name, start, 435 rb->strncpy(entry->name, start, FIELD_LEN);
433 MIN((intptr_t)end - (intptr_t)start, FIELD_LEN)); 436 start = end + 1;
434 start = end +1;
435 437
436 end = rb->strchr(start, '\0'); /* find eol */ 438 end = rb->strchr(start, '\0'); /* find eol */
437 len = (intptr_t)end - (intptr_t)&buffer[HEADER_LEN]; 439 len = end - &buffer[HEADER_LEN];
438 if (len > bytes_read + HEADER_LEN) 440 if (len > bytes_read + HEADER_LEN)
439 { 441 {
440 break; 442 break;
441 } 443 }
442 rb->strncpy(entry->password, start, 444 rb->strncpy(entry->password, start, FIELD_LEN);
443 MIN((intptr_t)end - (intptr_t)start, FIELD_LEN)); 445 start = end + 1;
444 start = end +1;
445 entry->used = true; 446 entry->used = true;
446 if (i + 1 < MAX_ENTRIES - 1) 447 if (i + 1 < MAX_ENTRIES - 1)
447 { 448 {
@@ -483,9 +484,10 @@ static void write_output(int fd)
483 if (entry->next) 484 if (entry->next)
484 entry = entry->next; 485 entry = entry->next;
485 } 486 }
487 *p++ = '\0'; /* mark the end of the list */
486 488
487 /* round up to a number divisible by BLOCK_SIZE */ 489 /* round up to a number divisible by BLOCK_SIZE */
488 size = (((intptr_t)p - (intptr_t)&buffer) / BLOCK_SIZE + 1) * BLOCK_SIZE; 490 size = ((p - buffer + BLOCK_SIZE - 1) / BLOCK_SIZE) * BLOCK_SIZE;
489 491
490 salt = rb->rand(); 492 salt = rb->rand();
491 make_key(); 493 make_key();