luks: Avoid crash when image does not contain a LUKS header
commitcad4b96b17ed4ad7882100efa0d9073ac9d8b11c
authorRichard W.M. Jones <rjones@redhat.com>
Tue, 10 Jan 2023 08:39:11 +0000 (10 08:39 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Tue, 10 Jan 2023 08:44:17 +0000 (10 08:44 +0000)
treefc9f1b8a4d2cd1335801805f310a7aceeaa379da
parente321ffb35fc555464305493cb64ad370e89d185c
luks: Avoid crash when image does not contain a LUKS header

We attempt to load the LUKS header in the prepare() callback.  If this
fails, h->h will be NULL and we'll crash in close() when we attempt to
access and free h->h->masterkey.

This crash could have been triggered another way: if open() followed
by close() was called, without prepare() or other callbacks.

Reported-by: Ming Xie
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2159581
filters/luks/luks-encryption.c