@DaneEveritt Guard against a nil-pointer if the container is not found; references pterodactyl/panel#2000

This commit is contained in:
Dane Everitt 2020-05-08 20:19:44 -07:00
parent ced8a5bcbd
commit b2cf222a3a
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -197,18 +197,33 @@ func (d *DockerEnvironment) Start() error {
return &suspendedError{} return &suspendedError{}
} }
c, err := d.Client.ContainerInspect(context.Background(), d.Server.Uuid) if c, err := d.Client.ContainerInspect(context.Background(), d.Server.Uuid); err != nil {
if err != nil && !client.IsErrNotFound(err) { // Do nothing if the container is not found, we just don't want to continue
// to the next block of code here. This check was inlined here to guard againt
// a nil-pointer when checking c.State below.
//
// @see https://github.com/pterodactyl/panel/issues/2000
if !client.IsErrNotFound(err) {
return errors.WithStack(err) return errors.WithStack(err)
} }
} else {
// No reason to try starting a container that is already running. // If the server is running update our internal state and continue on with the attach.
if c.State.Running { if c.State.Running {
d.Server.SetState(ProcessRunningState) d.Server.SetState(ProcessRunningState)
return d.Attach() return d.Attach()
} }
// Truncate the log file so we don't end up outputting a bunch of useless log information
// to the websocket and whatnot. Check first that the path and file exist before trying
// to truncate them.
if _, err := os.Stat(c.LogPath); err == nil {
if err := os.Truncate(c.LogPath, 0); err != nil {
return errors.WithStack(err)
}
}
}
d.Server.SetState(ProcessStartingState) d.Server.SetState(ProcessStartingState)
// Set this to true for now, we will set it to false once we reach the // Set this to true for now, we will set it to false once we reach the
// end of this chain. // end of this chain.
@ -221,15 +236,6 @@ func (d *DockerEnvironment) Start() error {
return errors.WithStack(err) return errors.WithStack(err)
} }
// Truncate the log file so we don't end up outputting a bunch of useless log information
// to the websocket and whatnot. Check first that the path and file exist before trying
// to truncate them.
if _, err := os.Stat(c.LogPath); err == nil {
if err := os.Truncate(c.LogPath, 0); err != nil {
return errors.WithStack(err)
}
}
// Update the configuration files defined for the server before beginning the boot process. // Update the configuration files defined for the server before beginning the boot process.
// This process executes a bunch of parallel updates, so we just block until that process // This process executes a bunch of parallel updates, so we just block until that process
// is completed. Any errors as a result of this will just be bubbled out in the logger, // is completed. Any errors as a result of this will just be bubbled out in the logger,