Skip to content

Commit e7b14f3

Browse files
committed
Make cwd required
Signed-off-by: Mrunal Patel <[email protected]>
1 parent 4c767d7 commit e7b14f3

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

libcontainer/init_linux.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ func finalizeNamespace(config *initConfig) error {
134134
if err := w.drop(); err != nil {
135135
return err
136136
}
137-
if config.Cwd != "" {
138-
if err := syscall.Chdir(config.Cwd); err != nil {
139-
return err
140-
}
137+
if err := syscall.Chdir(config.Cwd); err != nil {
138+
return err
141139
}
142140
return nil
143141
}

spec.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var specCommand = cli.Command{
5353
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
5454
"TERM=xterm",
5555
},
56+
Cwd: "/",
5657
},
5758
Hostname: "shell",
5859
Mounts: []specs.MountPoint{
@@ -290,6 +291,15 @@ var mountPropagationMapping = map[string]int{
290291
"": syscall.MS_PRIVATE | syscall.MS_REC,
291292
}
292293

294+
// validateSpec validates the fields in the spec
295+
// TODO: Add validation for other fields where applicable
296+
func validateSpec(spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec) error {
297+
if spec.Process.Cwd == "" {
298+
return fmt.Errorf("Cwd property must not be empty")
299+
}
300+
return nil
301+
}
302+
293303
// loadSpec loads the specification from the provided path.
294304
// If the path is empty then the default path will be "config.json"
295305
func loadSpec(cPath, rPath string) (spec *specs.LinuxSpec, rspec *specs.LinuxRuntimeSpec, err error) {
@@ -317,7 +327,10 @@ func loadSpec(cPath, rPath string) (spec *specs.LinuxSpec, rspec *specs.LinuxRun
317327
if err = json.NewDecoder(rf).Decode(&rspec); err != nil {
318328
return spec, rspec, err
319329
}
320-
return spec, rspec, checkSpecVersion(spec)
330+
if err := checkSpecVersion(spec); err != nil {
331+
return spec, rspec, err
332+
}
333+
return spec, rspec, validateSpec(spec, rspec)
321334
}
322335

323336
// checkSpecVersion makes sure that the spec version matches runc's while we are in the initial

start.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func startContainer(context *cli.Context, spec *specs.LinuxSpec, rspec *specs.Li
108108
// ensure that the container is always removed if we were the process
109109
// that created it.
110110
defer destroy(container)
111+
111112
process := newProcess(spec.Process)
112113

113114
// Support on-demand socket activation by passing file descriptors into the container init process.

0 commit comments

Comments
 (0)