]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
calendarspec: use ADD_SAFE for repeat offset calculation
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 28 Mar 2026 21:56:41 +0000 (21:56 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 30 Mar 2026 09:55:33 +0000 (10:55 +0100)
Use overflow-safe ADD_SAFE() instead of raw addition when
computing the next matching calendar component with repeat.
On overflow, skip the component instead of using a bogus value.

CID#1548052

Follow-up for a2eb5ea79c53620cfcf616e83bfac0c431247f86

src/shared/calendarspec.c

index dc13ae0f77994f11a3ea09230d75362bca0c0020..df371ac4f8cc72ea8280935864905981ebe7caf2 100644 (file)
@@ -1149,9 +1149,8 @@ static int find_matching_component(
                 } else if (c->repeat > 0) {
                         int k;
 
-                        k = start + ROUND_UP(*val - start, c->repeat);
-
-                        if ((!d_set || k < d) && (stop < 0 || k <= stop)) {
+                        if (ADD_SAFE(&k, start, ROUND_UP(*val - start, c->repeat)) &&
+                            (!d_set || k < d) && (stop < 0 || k <= stop)) {
                                 d = k;
                                 d_set = true;
                         }