Fix a possible segfault in deferred deactivation.

For device without a type code shoud not try to use
strcmp function.

This can happen for example if deferref flag is used
for device without proper DM-UUID where init_by_name
does not set know device type.

Thanks Clément Guérin for the report.

Fixes: #910
This commit is contained in:
Milan Broz
2024-10-02 10:55:37 +02:00
parent d35fb1e671
commit faeb0c3483
2 changed files with 7 additions and 1 deletions

View File

@@ -7081,12 +7081,15 @@ int crypt_convert(struct crypt_device *cd,
/* Internal access function to header pointer */
void *crypt_get_hdr(struct crypt_device *cd, const char *type)
{
assert(cd);
assert(type);
/* One type can be OPAL */
if (isLUKS2(type) && isLUKS2(cd->type))
return &cd->u.luks2.hdr;
/* If requested type differs, ignore it */
if (strcmp(cd->type, type))
if (!cd->type || strcmp(cd->type, type))
return NULL;
if (isPLAIN(cd->type))