calendarspec: reject strings that only contain a timezone

This makes " UTC" an illegal date specification.
This commit is contained in:
Douglas Christman 2016-11-24 12:21:37 -05:00
parent 408a51e156
commit 04773cb50a
2 changed files with 6 additions and 3 deletions

View File

@ -779,9 +779,6 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
assert(p);
assert(spec);
if (isempty(p))
return -EINVAL;
c = new0(CalendarSpec, 1);
if (!c)
return -ENOMEM;
@ -820,6 +817,11 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
}
}
if (isempty(p)) {
r = -EINVAL;
goto fail;
}
if (strcaseeq(p, "minutely")) {
r = const_chain(0, &c->microsecond);
if (r < 0)

View File

@ -202,6 +202,7 @@ int main(int argc, char* argv[]) {
test_next("Mon 2017-05~07/1 UTC", "", 12345, 1496016000000000);
assert_se(calendar_spec_from_string("test", &c) < 0);
assert_se(calendar_spec_from_string(" utc", &c) < 0);
assert_se(calendar_spec_from_string(" ", &c) < 0);
assert_se(calendar_spec_from_string("", &c) < 0);
assert_se(calendar_spec_from_string("7", &c) < 0);