1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #3881 from crosbymichael/no-all-number

Do not generate all numberic truncated ids
This commit is contained in:
Guillaume J. Charmes 2014-01-31 18:07:01 -08:00
commit c9f6e446ee

View file

@ -203,12 +203,20 @@ func ValidateID(id string) error {
} }
func GenerateID() string { func GenerateID() string {
id := make([]byte, 32) for {
_, err := io.ReadFull(rand.Reader, id) id := make([]byte, 32)
if err != nil { if _, err := io.ReadFull(rand.Reader, id); err != nil {
panic(err) // This shouldn't happen panic(err) // This shouldn't happen
}
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
} }
return hex.EncodeToString(id)
} }
// Image includes convenience proxy functions to its graph // Image includes convenience proxy functions to its graph