mirror of
https://github.com/restic/restic.git
synced 2026-11-06 07:19:21 +00:00
data: return an error for too large numbers in ParseDuration (#22163)
This commit is contained in:
1 parent
b5d0152014
commit
9a0b9e0eb5
3 files changed
+13
-1
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
Bugfix: Report an error for too large numbers in `--keep-within*` durations
|
||||||
|
|
||||||
|
Restic crashed with a stack trace when a number in a duration such as the one
|
||||||
|
passed to `restic forget --keep-within` did not fit into an integer. It now
|
||||||
|
reports an invalid argument instead.
|
||||||
|
|
||||||
|
https://github.com/restic/restic/pull/22163
|
||||||
@@ -65,7 +65,7 @@ func nextNumber(input string) (num int, rest string, err error) {
|
|||||||
|
|
||||||
num, err = strconv.Atoi(n)
|
num, err = strconv.Atoi(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return 0, input, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if negative {
|
if negative {
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ func TestNextNumber(t *testing.T) {
|
|||||||
{
|
{
|
||||||
input: "5", num: 5, rest: "",
|
input: "5", num: 5, rest: "",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: "99999999999999999999999999y", num: 0, rest: "99999999999999999999999999y", err: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@@ -82,6 +85,8 @@ func TestParseDuration(t *testing.T) {
|
|||||||
{input: "1y4m3w1d", err: true},
|
{input: "1y4m3w1d", err: true},
|
||||||
{input: "s", err: true},
|
{input: "s", err: true},
|
||||||
{input: "\xdf\x80", err: true}, // NKO DIGIT ZERO; we want ASCII digits
|
{input: "\xdf\x80", err: true}, // NKO DIGIT ZERO; we want ASCII digits
|
||||||
|
{input: "99999999999999999999999999y", err: true},
|
||||||
|
{input: "1y-99999999999999999999999999d", err: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|||||||
Reference in new issue
Block a user