Blob Blame Raw
From 1984e451d5ae2081996cbcfcc6d15dc9fde0259b Mon Sep 17 00:00:00 2001
From: Derek McGowan <derek@mcgstyle.net>
Date: Thu, 12 Jul 2018 16:40:45 -0700
Subject: [PATCH] Replace stringid with simple rand reader

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
---
 cmd/containerd/containerd.go                  |  6 ++
 cmd/ctr/main.go                               |  6 ++
 pkg/util/id.go                                |  9 +-
 5 files changed, 19 insertions(+), 102 deletions(-)

diff --git a/cmd/containerd/containerd.go b/cmd/containerd/containerd.go
index 563eb5a9..91e51939 100644
--- a/cmd/containerd/containerd.go
+++ b/cmd/containerd/containerd.go
@@ -18,7 +18,9 @@ package main
 
 import (
 	"fmt"
+	"math/rand"
 	"os"
+	"time"
 
 	_ "github.com/containerd/containerd/diff/walking/plugin"
 	_ "github.com/containerd/containerd/gc/scheduler"
@@ -43,6 +45,10 @@ import (
 	"github.com/sirupsen/logrus"
 )
 
+func init() {
+	rand.Seed(time.Now().UnixNano())
+}
+
 func main() {
 	app := command.App()
 	logrus.Warn("This customized containerd is only for CI test, DO NOT use it for distribution.")
diff --git a/cmd/ctr/main.go b/cmd/ctr/main.go
index 604e60e7..81e58efd 100644
--- a/cmd/ctr/main.go
+++ b/cmd/ctr/main.go
@@ -18,13 +18,19 @@ package main
 
 import (
 	"fmt"
+	"math/rand"
 	"os"
+	"time"
 
 	ctrapp "github.com/containerd/containerd/cmd/ctr/app"
 
 	cricli "github.com/containerd/cri/cli"
 )
 
+func init() {
+	rand.Seed(time.Now().UnixNano())
+}
+
 func main() {
 	app := ctrapp.New()
 	app.Commands = append(app.Commands, cricli.Command)
diff --git a/pkg/util/id.go b/pkg/util/id.go
index ae7fbdcc..11b0a70a 100644
--- a/pkg/util/id.go
+++ b/pkg/util/id.go
@@ -16,9 +16,14 @@ limitations under the License.
 
 package util
 
-import "github.com/docker/docker/pkg/stringid"
+import (
+	"encoding/hex"
+	"math/rand"
+)
 
 // GenerateID generates a random unique id.
 func GenerateID() string {
-	return stringid.GenerateNonCryptoID()
+	b := make([]byte, 32)
+	rand.Read(b)
+	return hex.EncodeToString(b)
 }