mirror of
https://github.com/restic/restic.git
synced 2025-10-30 01:38:35 +00:00
Merge pull request #5486 from greatroar/duration-panic
Avoid panic in duration parsing
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"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 {
|
||||
if !unicode.IsNumber(s) {
|
||||
if s < '0' || s > '9' {
|
||||
rest = input[i:]
|
||||
break
|
||||
}
|
||||
|
||||
@@ -37,6 +37,9 @@ func TestNextNumber(t *testing.T) {
|
||||
{
|
||||
input: "5d ", num: 5, rest: "d ",
|
||||
},
|
||||
{
|
||||
input: "5", num: 5, rest: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -78,6 +81,7 @@ func TestParseDuration(t *testing.T) {
|
||||
{input: "2w", err: true},
|
||||
{input: "1y4m3w1d", err: true},
|
||||
{input: "s", err: true},
|
||||
{input: "\xdf\x80", err: true}, // NKO DIGIT ZERO; we want ASCII digits
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
Reference in New Issue
Block a user