Skip to content

Commit

Permalink
Fix nil pointer dereference on CreateVM
Browse files Browse the repository at this point in the history
The system does not allow to create a VM with both rootfs and initrd
specified, that means we should be able to create a vm without initrd,
but the code had some strange assumption about that:

       160:         _, err = client.PutGuestBootSource(ctx, &fcmodels.BootSource{
       161:                 KernelImagePath: &cfg.BootSource.KernelImagePage,
       162:                 BootArgs:        *cfg.BootSource.BootArgs,
    => 163:                 InitrdPath:      *cfg.BootSource.InitrdPath,
       164:         })

At the same time, it can happen with BootArgs too as it's not a required
field.

Fixes #175
  • Loading branch information
yitsushi committed Oct 27, 2021
1 parent 3217c47 commit a126670
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions infrastructure/firecracker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,26 @@ func ApplyConfig(ctx context.Context, cfg *VmmConfig, client *firecracker.Client
return fmt.Errorf("putting %s network configuration: %w", guestIfaceName, err)
}
}
_, err = client.PutGuestBootSource(ctx, &fcmodels.BootSource{

bootSource := fcmodels.BootSource{
BootArgs: "",
InitrdPath: "",
KernelImagePath: &cfg.BootSource.KernelImagePage,
BootArgs: *cfg.BootSource.BootArgs,
InitrdPath: *cfg.BootSource.InitrdPath,
})
}

if cfg.BootSource.BootArgs != nil {
bootSource.BootArgs = *cfg.BootSource.BootArgs
}

if cfg.BootSource.InitrdPath != nil {
bootSource.InitrdPath = *cfg.BootSource.InitrdPath
}

_, err = client.PutGuestBootSource(ctx, &bootSource)
if err != nil {
return fmt.Errorf("failed to put machine bootsource: %w", err)
}

if cfg.Logger != nil {
_, err = client.PutLogger(ctx, &fcmodels.Logger{
LogPath: &cfg.Logger.LogPath,
Expand Down

0 comments on commit a126670

Please sign in to comment.