Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
Conflicts:
graph/load.go
| ... | ... |
@@ -14,6 +14,7 @@ import ( |
| 14 | 14 |
"github.com/docker/docker/image" |
| 15 | 15 |
"github.com/docker/docker/pkg/archive" |
| 16 | 16 |
"github.com/docker/docker/pkg/chrootarchive" |
| 17 |
+ "github.com/docker/docker/utils" |
|
| 17 | 18 |
) |
| 18 | 19 |
|
| 19 | 20 |
// Loads a set of images into the repository. This is the complementary of ImageExport. |
| ... | ... |
@@ -114,6 +115,10 @@ func (s *TagStore) recursiveLoad(eng *engine.Engine, address, tmpImageDir string |
| 114 | 114 |
log.Debugf("Error unmarshalling json", err)
|
| 115 | 115 |
return err |
| 116 | 116 |
} |
| 117 |
+ if err := utils.ValidateID(img.ID); err != nil {
|
|
| 118 |
+ log.Debugf("Error validating ID: %s", err)
|
|
| 119 |
+ return err |
|
| 120 |
+ } |
|
| 117 | 121 |
if img.Parent != "" {
|
| 118 | 122 |
if !s.graph.Exists(img.Parent) {
|
| 119 | 123 |
if err := s.recursiveLoad(eng, img.Parent, tmpImageDir); err != nil {
|
| ... | ... |
@@ -23,7 +23,6 @@ var ( |
| 23 | 23 |
ErrInvalidRepositoryName = errors.New("Invalid repository name (ex: \"registry.domain.tld/myrepos\")")
|
| 24 | 24 |
ErrDoesNotExist = errors.New("Image does not exist")
|
| 25 | 25 |
errLoginRequired = errors.New("Authentication is required.")
|
| 26 |
- validHex = regexp.MustCompile(`^([a-f0-9]{64})$`)
|
|
| 27 | 26 |
validNamespace = regexp.MustCompile(`^([a-z0-9_]{4,30})$`)
|
| 28 | 27 |
validRepo = regexp.MustCompile(`^([a-z0-9-_.]+)$`) |
| 29 | 28 |
) |
| ... | ... |
@@ -171,7 +170,8 @@ func validateRepositoryName(repositoryName string) error {
|
| 171 | 171 |
namespace = "library" |
| 172 | 172 |
name = nameParts[0] |
| 173 | 173 |
|
| 174 |
- if validHex.MatchString(name) {
|
|
| 174 |
+ // the repository name must not be a valid image ID |
|
| 175 |
+ if err := utils.ValidateID(name); err == nil {
|
|
| 175 | 176 |
return fmt.Errorf("Invalid repository name (%s), cannot specify 64-byte hexadecimal strings", name)
|
| 176 | 177 |
} |
| 177 | 178 |
} else {
|
| ... | ... |
@@ -31,6 +31,10 @@ type KeyValuePair struct {
|
| 31 | 31 |
Value string |
| 32 | 32 |
} |
| 33 | 33 |
|
| 34 |
+var ( |
|
| 35 |
+ validHex = regexp.MustCompile(`^([a-f0-9]{64})$`)
|
|
| 36 |
+) |
|
| 37 |
+ |
|
| 34 | 38 |
// Request a given URL and return an io.Reader |
| 35 | 39 |
func Download(url string) (resp *http.Response, err error) {
|
| 36 | 40 |
if resp, err = http.Get(url); err != nil {
|
| ... | ... |
@@ -190,11 +194,9 @@ func GenerateRandomID() string {
|
| 190 | 190 |
} |
| 191 | 191 |
|
| 192 | 192 |
func ValidateID(id string) error {
|
| 193 |
- if id == "" {
|
|
| 194 |
- return fmt.Errorf("Id can't be empty")
|
|
| 195 |
- } |
|
| 196 |
- if strings.Contains(id, ":") {
|
|
| 197 |
- return fmt.Errorf("Invalid character in id: ':'")
|
|
| 193 |
+ if ok := validHex.MatchString(id); !ok {
|
|
| 194 |
+ err := fmt.Errorf("image ID '%s' is invalid", id)
|
|
| 195 |
+ return err |
|
| 198 | 196 |
} |
| 199 | 197 |
return nil |
| 200 | 198 |
} |