Reject a retention duration longer than about 292 years (closes #289)
check / check (push) Failing after 3m36s
check / check (push) Failing after 3m36s
parseDuration multiplied each number by the length of its unit with no limit, so from 293y (or 15251w, 3559mo, 106752d, or a sum such as 200y200y) the result wrapped to a negative duration. The purge cutoff then lay in the future and every snapshot of the name was selected, for --older-than and --keep-newer-than alike. Each part is now checked before it is added, and a total past the largest time.Duration is rejected as an invalid duration, so nothing is deleted. Go units were already safe: time.ParseDuration rejects an overflow. With --prune the backup still runs before the duration is read; only the prune step fails. Model: opus-5-5
This commit was merged in pull request #328.
This commit is contained in:
@@ -111,6 +111,17 @@ func TestParseDuration(t *testing.T) {
|
||||
{"30 days", 0, true},
|
||||
{"30 days ago", 0, true},
|
||||
{"x7d", 0, true},
|
||||
// The largest time.Duration is about 292 years. A larger value
|
||||
// must be rejected, not wrapped to a negative one, which would
|
||||
// put the cutoff in the future and select every snapshot.
|
||||
{"292y", 292 * 365 * 24 * time.Hour, false},
|
||||
{"293y", 0, true},
|
||||
{"3559mo", 0, true},
|
||||
{"15251w", 0, true},
|
||||
{"106752d", 0, true},
|
||||
{"2562048h", 0, true},
|
||||
{"200y200y", 0, true},
|
||||
{"292y6mo", 0, true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user