runtime-v2: add validation for runtime name
add validation for runtime name, if runtime name is invalid,
containerd will got panic.
@@ -49,6 +49,9 @@ func Command(ctx context.Context, runtime, containerdAddress, path string, cmdAr
}
args = append(args, cmdArgs...)
name := BinaryName(runtime)
+ if name == "" {
+ return nil, fmt.Errorf("invalid runtime name %s, correct runtime name should format like io.containerd.runc.v1", runtime)
+ }
var cmdPath string
var lerr error
if cmdPath, lerr = exec.LookPath(name); lerr != nil {
@@ -69,10 +72,15 @@ func Command(ctx context.Context, runtime, containerdAddress, path string, cmdAr
return cmd, nil
}
-// BinaryName returns the shim binary name from the runtime name
+// BinaryName returns the shim binary name from the runtime name,
+// empty string returns means runtime name is invalid
func BinaryName(runtime string) string {
+ // runtime name should format like $prefix.name.version
parts := strings.Split(runtime, ".")
- // TODO: add validation for runtime
+ if len(parts) < 2 {
+ return ""
+ }
+
return fmt.Sprintf(shimBinaryFormat, parts[len(parts)-2], parts[len(parts)-1])
}
