util: prevent a panic when creating an fscrypt protector failed

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos 2025-01-22 14:33:55 +01:00
parent 72cfaaf3fc
commit 003e0b36a6

View File

@ -217,12 +217,14 @@ func initializeAndUnlock(
}
protector, err := fscryptactions.CreateProtector(fscryptContext, protectorName, keyFn, owner)
if err != nil {
if err != nil && protector != nil {
log.ErrorLog(ctx, "fscrypt: protector name=%s create failed: %v. reverting.", protectorName, err)
if revertErr := protector.Revert(); revertErr != nil {
return revertErr
}
return err
} else if err != nil {
return err
}