validate image ID properly & before load

Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
Upstream-commit: acf1720b3f6035f0ab2c9658371ae8302851ffa3
Component: engine
This commit is contained in:
unclejack
2014-11-27 23:55:03 +02:00
committed by Tibor Vass
parent 94c64ce8e8
commit ed1287419c
4 changed files with 15 additions and 8 deletions

View File

@ -31,6 +31,10 @@ type KeyValuePair struct {
Value string
}
var (
validHex = regexp.MustCompile(`^([a-f0-9]{64})$`)
)
// Request a given URL and return an io.Reader
func Download(url string) (resp *http.Response, err error) {
if resp, err = http.Get(url); err != nil {
@ -190,11 +194,9 @@ func GenerateRandomID() string {
}
func ValidateID(id string) error {
if id == "" {
return fmt.Errorf("Id can't be empty")
}
if strings.Contains(id, ":") {
return fmt.Errorf("Invalid character in id: ':'")
if ok := validHex.MatchString(id); !ok {
err := fmt.Errorf("image ID '%s' is invalid", id)
return err
}
return nil
}