Do not generate all numberic truncated ids
Fixes #3869 Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
23815414ea
commit
9b7054fd0b
14
image.go
14
image.go
|
@ -203,12 +203,20 @@ func ValidateID(id string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateID() string {
|
func GenerateID() string {
|
||||||
|
for {
|
||||||
id := make([]byte, 32)
|
id := make([]byte, 32)
|
||||||
_, err := io.ReadFull(rand.Reader, id)
|
if _, err := io.ReadFull(rand.Reader, id); err != nil {
|
||||||
if err != nil {
|
|
||||||
panic(err) // This shouldn't happen
|
panic(err) // This shouldn't happen
|
||||||
}
|
}
|
||||||
return hex.EncodeToString(id)
|
value := hex.EncodeToString(id)
|
||||||
|
// if we try to parse the truncated for as an int and we don't have
|
||||||
|
// an error then the value is all numberic and causes issues when
|
||||||
|
// used as a hostname. ref #3869
|
||||||
|
if _, err := strconv.Atoi(utils.TruncateID(value)); err == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Image includes convenience proxy functions to its graph
|
// Image includes convenience proxy functions to its graph
|
||||||
|
|
Loading…
Reference in New Issue