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 <LarsHenriksen@get2net.dk>
Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen 2018-06-04 21:28:44 +02:00 committed by Lukas Fleischer
parent 40eb6f809e
commit 163730cabf

View File

@ -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;
}