mirror of
https://github.com/restic/restic.git
synced 2025-12-12 08:22:08 +00:00
internal/restic: Fix panic in ParseDuration
Fixes #5485. Includes test case by @MichaelEischer.
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
|
||||||
|
|
||||||
"github.com/restic/restic/internal/errors"
|
"github.com/restic/restic/internal/errors"
|
||||||
)
|
)
|
||||||
@@ -52,7 +51,7 @@ func nextNumber(input string) (num int, rest string, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, s := range input {
|
for i, s := range input {
|
||||||
if !unicode.IsNumber(s) {
|
if s < '0' || s > '9' {
|
||||||
rest = input[i:]
|
rest = input[i:]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ func TestNextNumber(t *testing.T) {
|
|||||||
{
|
{
|
||||||
input: "5d ", num: 5, rest: "d ",
|
input: "5d ", num: 5, rest: "d ",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
input: "5", num: 5, rest: "",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@@ -78,6 +81,7 @@ func TestParseDuration(t *testing.T) {
|
|||||||
{input: "2w", err: true},
|
{input: "2w", err: true},
|
||||||
{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
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user