Skip to content

Commit f2628a7

Browse files
committed
utils_linux: Avoid panic when process is unset
As it can be since opencontainers/runtime-spec@c41ea83d (config: Make process optional, 2017-02-27, opencontainers/runtime-spec#701). Signed-off-by: W. Trevor King <[email protected]>
1 parent 595bea0 commit f2628a7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

utils_linux.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ func getDefaultImagePath(context *cli.Context) string {
9797

9898
// newProcess returns a new libcontainer Process with the arguments from the
9999
// spec and stdio from the current process.
100-
func newProcess(p specs.Process) (*libcontainer.Process, error) {
100+
func newProcess(p *specs.Process) (*libcontainer.Process, error) {
101+
if p == nil {
102+
return &libcontainer.Process{}, nil
103+
}
101104
lp := &libcontainer.Process{
102105
Args: p.Args,
103106
Env: p.Env,
@@ -261,7 +264,7 @@ func (r *runner) run(config *specs.Process) (int, error) {
261264
r.destroy()
262265
return -1, err
263266
}
264-
process, err := newProcess(*config)
267+
process, err := newProcess(config)
265268
if err != nil {
266269
r.destroy()
267270
return -1, err
@@ -291,7 +294,8 @@ func (r *runner) run(config *specs.Process) (int, error) {
291294
// with detaching containers, and then we get a tty after the container has
292295
// started.
293296
handler := newSignalHandler(r.enableSubreaper, r.notifySocket)
294-
tty, err := setupIO(process, rootuid, rootgid, config.Terminal, detach, r.consoleSocket)
297+
terminal := config != nil && config.Terminal
298+
tty, err := setupIO(process, rootuid, rootgid, terminal, detach, r.consoleSocket)
295299
if err != nil {
296300
r.destroy()
297301
return -1, err
@@ -353,17 +357,21 @@ func (r *runner) terminate(p *libcontainer.Process) {
353357

354358
func (r *runner) checkTerminal(config *specs.Process) error {
355359
detach := r.detach || (r.action == CT_ACT_CREATE)
360+
terminal := config != nil && config.Terminal
356361
// Check command-line for sanity.
357-
if detach && config.Terminal && r.consoleSocket == "" {
362+
if detach && terminal && r.consoleSocket == "" {
358363
return fmt.Errorf("cannot allocate tty if runc will detach without setting console socket")
359364
}
360-
if (!detach || !config.Terminal) && r.consoleSocket != "" {
365+
if (!detach || !terminal) && r.consoleSocket != "" {
361366
return fmt.Errorf("cannot use console socket if runc will not detach or allocate tty")
362367
}
363368
return nil
364369
}
365370

366371
func validateProcessSpec(spec *specs.Process) error {
372+
if spec == nil {
373+
return nil
374+
}
367375
if spec.Cwd == "" {
368376
return fmt.Errorf("Cwd property must not be empty")
369377
}

0 commit comments

Comments
 (0)