diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2014-08-18 15:13:46 +0200 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2014-08-18 15:18:11 +0200 |
commit | 76f151ff375f2985026f4d5d738c8e2c769a1bce (patch) | |
tree | 5a6a852fc23190f2037e3c9a6afaf52c3dfa02e0 /src/ical.c | |
parent | 0a2c4d20fe49c504b5bbb383afc97db340814bba (diff) | |
download | calcurse-76f151ff375f2985026f4d5d738c8e2c769a1bce.zip |
Correctly parse all types of iCal durations
This was supposed to be fixed in 6ca2535 (ical.c: Simplify and fix
ical_durtime2long(), 2014-07-28) but some cases were not covered.
Reported-by: HÃ¥kan Jerning <jerning@home.se>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/ical.c')
-rw-r--r-- | src/ical.c | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -510,6 +510,7 @@ static long ical_datetime2long(char *datestr, ical_vevent_e * type) static long ical_durtime2long(char *timestr) { char *p; + int bytes_read; unsigned hour = 0, min = 0, sec = 0; if ((p = strchr(timestr, 'T')) == NULL) @@ -517,16 +518,24 @@ static long ical_durtime2long(char *timestr) p++; if (strchr(p, 'H')) { - if (sscanf(p, "%uH%uM%uS", &hour, &min, &sec) != 3) + if (sscanf(p, "%uH%n", &hour, &bytes_read) != 1) return 0; - } else if (strchr(p, 'M')) { - if (sscanf(p, "%uM%uS", &min, &sec) != 2) + p += bytes_read; + } + if (strchr(p, 'M')) { + if (sscanf(p, "%uM%n", &min, &bytes_read) != 1) return 0; - } else if (strchr(p, 'S')) { - if (sscanf(p, "%uS", &sec) != 1) + p += bytes_read; + } + if (strchr(p, 'S')) { + if (sscanf(p, "%uM%n", &sec, &bytes_read) != 1) return 0; + p += bytes_read; } + if (hour == 0 && min == 0 && sec == 0) + return 0; + return hour * HOURINSEC + min * MININSEC + sec; } |