Fix out-of-bounds memory access
Do not try to access freed day items. This also fixes unexpected selection changes after modifying appointments or events. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
77d5b10ee0
commit
ab9256adf0
@ -49,6 +49,15 @@ int count, reg;
|
|||||||
static void do_storage(int day_changed)
|
static void do_storage(int day_changed)
|
||||||
{
|
{
|
||||||
struct day_item *day = ui_day_selitem();
|
struct day_item *day = ui_day_selitem();
|
||||||
|
union aptev_ptr item;
|
||||||
|
|
||||||
|
if (day) {
|
||||||
|
/*
|
||||||
|
* day_process_storage() rebuilds the vector of day items, so
|
||||||
|
* we need to save the reference to the actual item here.
|
||||||
|
*/
|
||||||
|
item = day->item;
|
||||||
|
}
|
||||||
|
|
||||||
day_process_storage(ui_calendar_get_slctd_day(), day_changed);
|
day_process_storage(ui_calendar_get_slctd_day(), day_changed);
|
||||||
ui_day_load_items();
|
ui_day_load_items();
|
||||||
@ -56,7 +65,7 @@ static void do_storage(int day_changed)
|
|||||||
if (day_changed)
|
if (day_changed)
|
||||||
ui_day_sel_reset();
|
ui_day_sel_reset();
|
||||||
else if (day)
|
else if (day)
|
||||||
ui_day_set_selitem(day);
|
ui_day_set_selitem_by_aptev_ptr(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void key_generic_change_view(void)
|
static inline void key_generic_change_view(void)
|
||||||
|
@ -772,6 +772,7 @@ int day_check_if_item(struct date);
|
|||||||
unsigned day_chk_busy_slices(struct date, int, int *);
|
unsigned day_chk_busy_slices(struct date, int, int *);
|
||||||
struct day_item *day_cut_item(long, int);
|
struct day_item *day_cut_item(long, int);
|
||||||
int day_paste_item(struct day_item *, long);
|
int day_paste_item(struct day_item *, long);
|
||||||
|
int day_get_position_by_aptev_ptr(union aptev_ptr);
|
||||||
int day_get_position(struct day_item *);
|
int day_get_position(struct day_item *);
|
||||||
struct day_item *day_get_item(int);
|
struct day_item *day_get_item(int);
|
||||||
unsigned day_item_count(int);
|
unsigned day_item_count(int);
|
||||||
@ -1044,6 +1045,7 @@ void todo_free_list(void);
|
|||||||
|
|
||||||
/* ui-day.c */
|
/* ui-day.c */
|
||||||
struct day_item *ui_day_selitem(void);
|
struct day_item *ui_day_selitem(void);
|
||||||
|
void ui_day_set_selitem_by_aptev_ptr(union aptev_ptr);
|
||||||
void ui_day_set_selitem(struct day_item *);
|
void ui_day_set_selitem(struct day_item *);
|
||||||
void ui_day_item_add(void);
|
void ui_day_item_add(void);
|
||||||
void ui_day_item_delete(unsigned);
|
void ui_day_item_delete(unsigned);
|
||||||
|
@ -695,20 +695,25 @@ int day_paste_item(struct day_item *p, long date)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the position corresponding to a given item. */
|
/* Returns the position corresponding to a given item. */
|
||||||
int day_get_position(struct day_item *needle)
|
int day_get_position_by_aptev_ptr(union aptev_ptr aptevp)
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
VECTOR_FOREACH(&day_items, n) {
|
VECTOR_FOREACH(&day_items, n) {
|
||||||
struct day_item *p = VECTOR_NTH(&day_items, n);
|
struct day_item *p = VECTOR_NTH(&day_items, n);
|
||||||
/* Compare pointers. */
|
/* Compare pointers. */
|
||||||
if (p->item.ev == needle->item.ev)
|
if (p->item.ev == aptevp.ev)
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int day_get_position(struct day_item *needle)
|
||||||
|
{
|
||||||
|
return day_get_position_by_aptev_ptr(needle->item);
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns a structure containing the selected item. */
|
/* Returns a structure containing the selected item. */
|
||||||
struct day_item *day_get_item(int item_number)
|
struct day_item *day_get_item(int item_number)
|
||||||
{
|
{
|
||||||
|
@ -46,13 +46,18 @@ struct day_item *ui_day_selitem(void)
|
|||||||
return day_get_item(listbox_get_sel(&lb_apt));
|
return day_get_item(listbox_get_sel(&lb_apt));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_day_set_selitem(struct day_item *day)
|
void ui_day_set_selitem_by_aptev_ptr(union aptev_ptr p)
|
||||||
{
|
{
|
||||||
int n = day_get_position(day);
|
int n = day_get_position_by_aptev_ptr(p);
|
||||||
if (n >= 0)
|
if (n >= 0)
|
||||||
listbox_set_sel(&lb_apt, n);
|
listbox_set_sel(&lb_apt, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ui_day_set_selitem(struct day_item *day)
|
||||||
|
{
|
||||||
|
ui_day_set_selitem_by_aptev_ptr(day->item);
|
||||||
|
}
|
||||||
|
|
||||||
/* Request the user to enter a new time. */
|
/* Request the user to enter a new time. */
|
||||||
static int day_edit_time(int time, unsigned *new_hour,
|
static int day_edit_time(int time, unsigned *new_hour,
|
||||||
unsigned *new_minute)
|
unsigned *new_minute)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user