summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2013-02-27 11:00:26 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2013-02-27 11:36:29 +0100
commit9907069f442c56c90b67accb2d8fbd046dfce6db (patch)
treeaa7c5e31f7ede9e5262de253641948ec8b0dff11 /src
parent43bdd12254082c58b04e0d3b3032569443e96e4f (diff)
downloadcalcurse-9907069f442c56c90b67accb2d8fbd046dfce6db.tar.gz
calcurse-9907069f442c56c90b67accb2d8fbd046dfce6db.zip
Validate date/time when scanning items
Bail out when reading dates such as "02/30/2013" from the appointments file. These *could* be converted into valid dates but since we never write invalid dates to that file, these indicate a user error. Fixes following test cases: * appointment-009.sh * appointment-012.sh * appointment-016.sh * appointment-019.sh * event-003.sh Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src')
-rw-r--r--src/apoint.c6
-rw-r--r--src/event.c4
-rw-r--r--src/recur.c19
3 files changed, 29 insertions, 0 deletions
diff --git a/src/apoint.c b/src/apoint.c
index 889c371..ca400e9 100644
--- a/src/apoint.c
+++ b/src/apoint.c
@@ -165,6 +165,12 @@ struct apoint *apoint_scan(FILE * f, struct tm start, struct tm end, char state,
char buf[BUFSIZ], *newline;
time_t tstart, tend;
+ EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
+ !check_date(end.tm_year, end.tm_mon, end.tm_mday) ||
+ !check_time(start.tm_hour, start.tm_min) ||
+ !check_time(end.tm_hour, end.tm_min),
+ _("date error in appointment"));
+
/* Read the appointment description */
if (!fgets(buf, sizeof buf, f))
return NULL;
diff --git a/src/event.c b/src/event.c
index b1186a3..637dd6d 100644
--- a/src/event.c
+++ b/src/event.c
@@ -125,6 +125,10 @@ struct event *event_scan(FILE * f, struct tm start, int id, char *note)
char buf[BUFSIZ], *nl;
time_t tstart;
+ EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
+ !check_time(start.tm_hour, start.tm_min),
+ _("date error in event"));
+
/* Read the event description */
if (!fgets(buf, sizeof buf, f))
return NULL;
diff --git a/src/recur.c b/src/recur.c
index 6a3a902..8a2f79f 100644
--- a/src/recur.c
+++ b/src/recur.c
@@ -325,6 +325,14 @@ struct recur_apoint *recur_apoint_scan(FILE * f, struct tm start, struct tm end,
char buf[BUFSIZ], *nl;
time_t tstart, tend, tuntil;
+ EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
+ !check_date(end.tm_year, end.tm_mon, end.tm_mday) ||
+ !check_time(start.tm_hour, start.tm_min) ||
+ !check_time(end.tm_hour, end.tm_min) ||
+ (until.tm_year != 0 && !check_date(until.tm_year, until.tm_mon,
+ until.tm_mday)),
+ _("date error in appointment"));
+
/* Read the appointment description */
if (!fgets(buf, sizeof buf, f))
return NULL;
@@ -368,6 +376,12 @@ struct recur_event *recur_event_scan(FILE * f, struct tm start, int id,
char buf[BUFSIZ], *nl;
time_t tstart, tuntil;
+ EXIT_IF(!check_date(start.tm_year, start.tm_mon, start.tm_mday) ||
+ !check_time(start.tm_hour, start.tm_min) ||
+ (until.tm_year != 0 && !check_date(until.tm_year, until.tm_mon,
+ until.tm_mday)),
+ _("date error in event"));
+
/* Read the event description */
if (!fgets(buf, sizeof buf, f))
return NULL;
@@ -750,6 +764,11 @@ void recur_exc_scan(llist_t * lexc, FILE * data_file)
&day.tm_mon, &day.tm_mday, &day.tm_year) != 3) {
EXIT(_("syntax error in item date"));
}
+
+ EXIT_IF(!check_date(day.tm_year, day.tm_mon, day.tm_mday) ||
+ !check_time(day.tm_hour, day.tm_min),
+ _("date error in item exception"));
+
day.tm_hour = 0;
day.tm_min = day.tm_sec = 0;
day.tm_isdst = -1;