Skip to content

Commit 671883e

Browse files
authored
Merge pull request #301 from Mashimiao/validate-add-args-check
validate: add args validation
2 parents 2d92f65 + 113fd04 commit 671883e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

validate/validate.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,31 @@ func (v *Validator) CheckProcess() (msgs []string) {
218218
}
219219
}
220220

221+
if len(process.Args) == 0 {
222+
msgs = append(msgs, fmt.Sprintf("args must not be empty"))
223+
} else {
224+
if filepath.IsAbs(process.Args[0]) {
225+
var rootfsPath string
226+
if filepath.IsAbs(v.spec.Root.Path) {
227+
rootfsPath = v.spec.Root.Path
228+
} else {
229+
rootfsPath = filepath.Join(v.bundlePath, v.spec.Root.Path)
230+
}
231+
absPath := filepath.Join(rootfsPath, process.Args[0])
232+
fileinfo, err := os.Stat(absPath)
233+
if os.IsNotExist(err) {
234+
logrus.Warnf("executable %q is not available in rootfs currently", process.Args[0])
235+
} else if err != nil {
236+
msgs = append(msgs, err.Error())
237+
} else {
238+
m := fileinfo.Mode()
239+
if m.IsDir() || m&0111 == 0 {
240+
msgs = append(msgs, fmt.Sprintf("arg %q is not executable", process.Args[0]))
241+
}
242+
}
243+
}
244+
}
245+
221246
for index := 0; index < len(process.Capabilities); index++ {
222247
capability := process.Capabilities[index]
223248
if !capValid(capability) {

0 commit comments

Comments
 (0)