summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-10 10:25:01 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-10 13:06:32 +0200
commit3aff2ae9d5427498f673bcb086d3439d2047e6c9 (patch)
tree637a10a012cb08e3ad1005c81930923111318982
parent4f23345592f9b2822a4f96f947230c9112fd1d4a (diff)
downloadsystemd-3aff2ae9d5427498f673bcb086d3439d2047e6c9.tar.gz
shared/calendarspec: fix printing of second ranges which start with 0
0..3 is not the same as 0..infinity, we need to check both ends of the range. This logic was added in 3215e35c405278491f55fb486d349f132e93f516, and back then the field was called .value. .stop was added later and apparently wasn't taken into account here.
-rw-r--r--src/shared/calendarspec.c2
-rw-r--r--src/test/test-calendarspec.c5
-rw-r--r--test/fuzz/fuzz-calendarspec/cant-parse-printed1
-rw-r--r--test/fuzz/fuzz-calendarspec/print-loses-spec1
4 files changed, 8 insertions, 1 deletions
diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c
index 51ade0e887..273a38f1fa 100644
--- a/src/shared/calendarspec.c
+++ b/src/shared/calendarspec.c
@@ -298,7 +298,7 @@ static void format_chain(FILE *f, int space, const CalendarComponent *c, bool us
return;
}
- if (usec && c->start == 0 && c->repeat == USEC_PER_SEC && !c->next) {
+ if (usec && c->start == 0 && c->stop < 0 && c->repeat == USEC_PER_SEC && !c->next) {
fputc('*', f);
return;
}
diff --git a/src/test/test-calendarspec.c b/src/test/test-calendarspec.c
index cf6965dd3c..5508f8b833 100644
--- a/src/test/test-calendarspec.c
+++ b/src/test/test-calendarspec.c
@@ -162,6 +162,8 @@ TEST(calendar_spec_one) {
test_one("00:00:1.0..3.8", "*-*-* 00:00:01..03");
test_one("00:00:01..03", "*-*-* 00:00:01..03");
test_one("00:00:01/2,02..03", "*-*-* 00:00:01/2,02..03");
+ test_one("*:4,30:0..3", "*-*-* *:04,30:00..03");
+ test_one("*:4,30:0/1", "*-*-* *:04,30:*");
test_one("*-*~1 Utc", "*-*~01 00:00:00 UTC");
test_one("*-*~05,3 ", "*-*~03,05 00:00:00");
test_one("*-*~* 00:00:00", "*-*-* 00:00:00");
@@ -252,6 +254,9 @@ TEST(calendar_spec_from_string) {
assert_se(calendar_spec_from_string("00:00:2300", &c) == -ERANGE);
assert_se(calendar_spec_from_string("00:00:18446744073709551615", &c) == -ERANGE);
assert_se(calendar_spec_from_string("@88588582097858858", &c) == -ERANGE);
+ assert_se(calendar_spec_from_string("*:4,30:*,5", &c) == -EINVAL);
+ assert_se(calendar_spec_from_string("*:4,30:5,*", &c) == -EINVAL);
+ assert_se(calendar_spec_from_string("*:4,30:*\n", &c) == -EINVAL);
}
DEFINE_TEST_MAIN(LOG_INFO);
diff --git a/test/fuzz/fuzz-calendarspec/cant-parse-printed b/test/fuzz/fuzz-calendarspec/cant-parse-printed
new file mode 100644
index 0000000000..e2c82a620e
--- /dev/null
+++ b/test/fuzz/fuzz-calendarspec/cant-parse-printed
@@ -0,0 +1 @@
+*:4,30:0..5,0 \ No newline at end of file
diff --git a/test/fuzz/fuzz-calendarspec/print-loses-spec b/test/fuzz/fuzz-calendarspec/print-loses-spec
new file mode 100644
index 0000000000..5e36de2e87
--- /dev/null
+++ b/test/fuzz/fuzz-calendarspec/print-loses-spec
@@ -0,0 +1 @@
+*:4,30:0..3 \ No newline at end of file