From 163730cabfa16bd044d3f68a0013f8adee551bbe Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Mon, 4 Jun 2018 21:28:44 +0200 Subject: Fix end-before-start inconsistency Due to deficient validation, it is possible to get an inconsistent database with an appointment that ends before it begins. Edit an existing one and specify an end time by a date that precedes the start date, or create a new one and give a date as end time that precedes the start. Then exit calcurse; on restart it will report a data error and exit. Signed-off-by: Lars Henriksen Signed-off-by: Lukas Fleischer --- src/ui-day.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ui-day.c b/src/ui-day.c index ab1f80b..9ce7ddd 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -111,13 +111,14 @@ static int day_edit_duration(int start, int dur, unsigned *new_duration) end = start + dur; ret = parse_datetime(timestr, &end); /* - * If the user enters a end time which is smaller than - * the start time, assume that the time belongs to the + * If the user enters no date and an end time which is smaller + * than the start time, assume that the time belongs to the * next day. */ if (!(ret & PARSE_DATETIME_HAS_DATE) && end < start) end = date_sec_change(end, 0, 1); - if (ret) { + /* Always check that the end comes after the start. */ + if (ret && start <= end) { *new_duration = end - start; break; } @@ -568,13 +569,14 @@ void ui_day_item_add(void) end = start; ret = parse_datetime(item_time, &end); /* - * If the user enters a end time which is smaller than - * the start time, assume that the time belongs to the - * next day. + * If the user enters no date and an end time which is + * smaller than the start time, assume that the time + * belongs to the next day. */ if (!(ret & PARSE_DATETIME_HAS_DATE) && end < start) end = date_sec_change(end, 0, 1); - if (ret) { + /* Always check that the end comes after the start. */ + if (ret && start <= end) { dur = end - start; break; } -- cgit v1.2.3-54-g00ecf