aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2018-06-04 21:28:44 +0200
committerLukas Fleischer <lfleischer@calcurse.org>2018-06-05 05:52:39 +0200
commit163730cabfa16bd044d3f68a0013f8adee551bbe (patch)
treeac66cd5e315dc26c38284b686aa8211423f77c17
parent40eb6f809eb22770543fe5ec6c0fc1fc1c9297df (diff)
downloadcalcurse-163730cabfa16bd044d3f68a0013f8adee551bbe.tar.gz
calcurse-163730cabfa16bd044d3f68a0013f8adee551bbe.zip
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>
-rw-r--r--src/ui-day.c16
1 files 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;
}