lib: fix potential segfault in LUKS2_token_buffer_free

The value of h may be NULL. Check it vefore visiting its
memeber to avoid segfault.

Signed-off-by: Lixiaokeng <lixiaokeng@huawei.com>
Signed-off-by: Linfeilong <linfeilong@huawei.com>
This commit is contained in:
lixiaokeng
2020-11-09 09:45:42 +08:00
committed by Milan Broz
parent 0d90efac88
commit 78f33946f1

View File

@@ -329,7 +329,7 @@ static void LUKS2_token_buffer_free(struct crypt_device *cd,
{
const crypt_token_handler *h = LUKS2_token_handler(cd, token);
if (h->buffer_free)
if (h && h->buffer_free)
h->buffer_free(buffer, buffer_len);
else {
crypt_safe_memzero(buffer, buffer_len);