nil deref fix
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-01-15 15:38:12 +11:00
parent debac1f684
commit 645a20829f
2 changed files with 16 additions and 3 deletions

View File

@@ -436,7 +436,12 @@ SELECT
COALESCE(agg.any_creation, agg.first_present, 0) AS "CreationTime", COALESCE(agg.any_creation, agg.first_present, 0) AS "CreationTime",
CASE CASE
WHEN NULLIF(agg.inv_deletion, 0) IS NOT NULL THEN NULLIF(agg.inv_deletion, 0) WHEN NULLIF(agg.inv_deletion, 0) IS NOT NULL THEN NULLIF(agg.inv_deletion, 0)
WHEN totals.max_snapshot IS NOT NULL AND agg.last_present < totals.max_snapshot THEN COALESCE(NULLIF(agg.any_deletion, 0), totals.max_snapshot, agg.last_present) WHEN totals.max_snapshot IS NOT NULL AND agg.last_present < totals.max_snapshot THEN COALESCE(
NULLIF(agg.any_deletion, 0),
(SELECT MIN(s2."SnapshotTime") FROM snapshots s2 WHERE s2."SnapshotTime" > agg.last_present),
totals.max_snapshot,
agg.last_present
)
ELSE NULLIF(agg.any_deletion, 0) ELSE NULLIF(agg.any_deletion, 0)
END AS "DeletionTime", END AS "DeletionTime",
( (

View File

@@ -404,10 +404,14 @@ func (v *Vcenter) GetClusterFromHost(hostRef *types.ManagedObjectReference) (str
v.Logger.Error("cant get host", "error", err) v.Logger.Error("cant get host", "error", err)
return "", err return "", err
} }
if host == nil {
v.Logger.Warn("host lookup returned nil", "host_ref", hostRef)
return "", nil
}
v.Logger.Debug("host parent", "parent", host.Parent) v.Logger.Debug("host parent", "parent", host.Parent)
if host.Parent.Type == "ClusterComputeResource" { if host.Parent != nil && host.Parent.Type == "ClusterComputeResource" {
// Retrieve properties of the compute resource // Retrieve properties of the compute resource
var moCompute mo.ComputeResource var moCompute mo.ComputeResource
err = v.client.RetrieveOne(v.ctx, *host.Parent, nil, &moCompute) err = v.client.RetrieveOne(v.ctx, *host.Parent, nil, &moCompute)
@@ -651,7 +655,7 @@ func (v *Vcenter) GetVMFolderPath(vm mo.VirtualMachine) (string, error) {
folderPath := "" folderPath := ""
//v.Logger.Debug("parent is", "parent", parentRef) //v.Logger.Debug("parent is", "parent", parentRef)
for parentRef.Type != "Datacenter" { for parentRef != nil && parentRef.Type != "Datacenter" {
// Retrieve the parent object // Retrieve the parent object
//parentObj, err := finder.ObjectReference(v.ctx, *parentRef) //parentObj, err := finder.ObjectReference(v.ctx, *parentRef)
//if err != nil { //if err != nil {
@@ -681,5 +685,9 @@ func (v *Vcenter) GetVMFolderPath(vm mo.VirtualMachine) (string, error) {
//break //break
} }
if parentRef == nil {
return "", fmt.Errorf("folder traversal terminated early for VM %s", vm.Name)
}
return folderPath, nil return folderPath, nil
} }